home *** CD-ROM | disk | FTP | other *** search
/ Enter 2007 April / ENTER_CD_04_07.iso / Internet / WinHTTrack 3.23 / httrack-3.23.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-02-23  |  101.8 KB  |  2,952 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. #include "htsbase.h"
  12.  
  13. // Ras
  14. #if USE_RAS 
  15. #include "RasLoad.h"
  16. #endif
  17.  
  18. #include <afxdisp.h>
  19. #include "ras.h"
  20.  
  21. //#include "ShellDoc.h"
  22. //#include "ShellView.h"
  23.  
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29.  
  30. // PATCH-->
  31. // PATCH-->
  32. #include "about.h"
  33. #include "infoend.h"
  34.  
  35. // flag de termination
  36. int termine=0;
  37. int termine_requested=0;
  38. int shell_terminated=0;
  39. int soft_term_requested=0;
  40. FILE* fp_debug=NULL;
  41.  
  42. #include "stdafx.h"
  43. #include "Shell.h"
  44. #include "process.h"
  45. //#include "ShellDoc.h"
  46. //#include "ShellView.h"
  47. //#include "essai.h"
  48. //#include "get.h"
  49. //#include "parameter.h"
  50. extern "C" {
  51.   #include "htssystem.h"
  52. }
  53. #include "Wid1.h"
  54. #include "trans.h"
  55. #include "InfoUrl.h"
  56. //#include "option.h"
  57. //#include "filter.h"
  58. //#include "wizard.h"
  59. //
  60. #include "maintab.h"
  61. //
  62. #include "MemRegister.h"
  63.  
  64. // LANG
  65. #include "newlang.h"
  66.  
  67.  
  68. // PATCH-->
  69. //#include "wizard2.h"
  70. //#include "WizLinks.h"
  71.  
  72. #include "inprogress.h"
  73.  
  74. #include "SYS\TIMEB.H"
  75.  
  76. // htswrap_add
  77. extern "C" {
  78.   #include "htswrap.h"
  79. };
  80.  
  81. // --- --- --- --- Options --- --- --- ---
  82.  
  83. #define MAX_LEN_INPROGRESS 32
  84.  
  85. // lancement en multithread du shell ET de gethostbyname
  86. #define SHELL_MULTITHREAD 1
  87. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  88. // --- --- --- --- Options --- --- --- ---
  89. //int INREDRAW_LOCKED=0;      // refresh graphique en cours
  90. //int INFILLMEM_LOCKED=0;     // refresh mΘmoire en cours
  91. int HTTRACK_result=0;
  92. //
  93. CInfoUrl* _Cinprogress_inst=NULL;
  94.  
  95. extern HICON httrack_icon;
  96.  
  97. /* Main splitter frame */
  98. #include "DialogContainer.h"
  99. #include "splitter.h"
  100. extern CSplitterFrame* this_CSplitterFrame;
  101.  
  102. /* Main WizTab frame */
  103. #include "WizTab.h"
  104. extern CWizTab* this_CWizTab;
  105. /* Argh - pas de domodal dans des autres threads ?!?! */
  106. char WIZ_question[1000];
  107. char WIZ_reponse[1000];
  108.  
  109.  
  110. // Fonctionnement des THREADS:
  111. //
  112. // principal ---> robot & refresh data (thread 1)
  113. //           ---> refresh graphique    (thread 2)
  114. //           GO!> boucle gestion domodal() et boutons
  115. // arrΩt: principal demande l'arrΩt (termine_requested)
  116. //        thread1 active termine et que thread2 ait fini de refresher
  117. //        thread2 se termine
  118. //        thread1 retourne 0 α hts_loop
  119. //        le robot termine
  120. //        le thread1 active termine, termine le formulaire et se termine
  121. //        principal ayant quittΘ le formulaire affiche le message de fin
  122.  
  123.  
  124. // htslib.c
  125. extern "C" {
  126.   HTSEXT_API void qsec2str(char *st,TStamp t);
  127. }
  128.  
  129. // construction index gΘnΘral
  130. // void Build_TopIndex();
  131.  
  132. void compute_options() ;
  133. char* connversion(char chaine[10000]);
  134. void lance(void);
  135. int check_continue(char* pathlog);
  136. int inprogress_refresh();
  137. //int inprogress_refresh_scan();
  138. void Write_profile(CString path,int load_path);
  139. void Read_profile(CString path,int load_path);
  140.  
  141.  
  142. // dΘja fait mais bon
  143. #define HTS_WIN 1
  144.  
  145. extern "C" {
  146.   #include "htscore.h"
  147. }
  148.  
  149. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  150.  
  151. char LINE[32768];
  152. char OPTIONurl[32000];
  153. char OPTIONfilelist[HTS_URLMAXSIZE*2];
  154. char OPTIONproxy[500];
  155. char OPTIONproxyftp[8];
  156. char OPTIONport[100];
  157. char OPTIONdepth[20];
  158. char OPTIONextdepth[20];
  159. char OPTIONget[10];
  160. //char OPTIONlevel[10];
  161. char OPTIONwhere[8];
  162. char OPTIONmeth[8];
  163. char OPTIONmaxfile[100];
  164. char OPTIONmax[100];
  165. char OPTIONfrag[100];
  166. char OPTIONconn[100];
  167. char OPTIONtog[10];
  168. char OPTIONcache[8];
  169. char OPTIONrobots[8];
  170. char choixdeb[8];
  171. char build[256];
  172. char filtre[32];
  173. char OPTIONhtmlfirst[8];
  174. char OPTIONindex[8];
  175. char OPTIONindex2[8];
  176. char OPTIONdos[8];
  177. char OPTIONtime[20];
  178. char OPTIONrate[20];
  179. char OPTIONhostquit[20];
  180. char OPTIONka[20];
  181. char OPTIONuser[256];
  182. char OPTIONfooter[256];
  183. char OPTIONlog[8];
  184. char OPTIONtestall[8];
  185. char OPTIONparseall[8];
  186. char OPTIONlink[8];
  187. char OPTIONpath[1000];
  188. char OPTIONretry[16];
  189. char OPTIONerrpage[8];
  190. char OPTIONexternal[8];
  191. char OPTIONnopurge[8];
  192. char OPTIONhidepwd[8];
  193. char OPTIONhidequery[8];
  194. char OPTIONcookies[8];
  195. char OPTIONchecktype[8];
  196. char OPTIONparsejava[8];
  197. char OPTIONCache2[8];
  198. char OPTIONlogtype[8];
  199. char OPTIONnorecatch[8];
  200. char OPTIONtoler[8];
  201. char OPTIONupdhack[8];
  202. char OPTIONhttp10[8];
  203. //-->
  204. char OPTIONwaittime[32];
  205. char OPTIONmaxtime[32];
  206. char OPTIONmaxrate[32];
  207. char OPTIONmaxconn[32];
  208. char OPTIONmaxlinks[32];
  209. char OPTIONhh[32];
  210. char OPTIONmm[32];
  211. char OPTIONss[32];
  212. //
  213. char buff_filtres[8192];
  214. char buff_MIME[8192];
  215. // RAS
  216. char OPTION_RasString[256];
  217. RASDIALPARAMS OPTION_dial;
  218.  
  219. // Fichier tempo
  220. FILE* tmpf=NULL;
  221. MemRegister tmpm;
  222.  
  223. CNewProj* dialog0=NULL;
  224. Wid1* dialog1=NULL;
  225. Ctrans* dialog2=NULL;
  226. //Coption dialog3;
  227. //Cfilter diafiltre;
  228. /*
  229. wizard diawiz;
  230. wizard2 diawiz2;
  231. WizLinks diawiz3;
  232. */
  233. //
  234. CMainTab* maintab=NULL;
  235. CShellApp* CShellApp_app=NULL;
  236.  
  237. #include "infoend.h"
  238. extern Cinfoend* this_Cinfoend;
  239.  
  240.  
  241. // PATCH-->
  242. Cinprogress* inprogress=NULL;
  243.  
  244. // nbre de slides
  245. t_StatsBuffer StatsBuffer[NStatsBuffer];
  246. void* StatsBufferback=NULL;
  247. int StatsBufferback_max=0;
  248. InpInfo SInfo;
  249.  
  250. #if USE_RAS
  251. // Chargement des librairies RAS
  252. CDynamicRAS* LibRas=NULL;
  253. int LibRasUse=0;
  254. //
  255. int connected=0;
  256. int disconnect=0;
  257. HRASCONN conn = NULL;
  258. int has_started=0;
  259. char connected_err[1000]="";
  260. #endif
  261.  
  262. // pour message final
  263. extern char end_mirror_msg[8192];
  264. #include "winhttrack.h"
  265. extern CWinHTTrackApp* this_app;
  266.  
  267.  
  268. // PATCH-->
  269. // PATCH-->
  270. // FIN PATCH
  271.  
  272.  
  273. /////////////////////////////////////////////////////////////////////////////
  274. // CShellApp
  275.  
  276. /*
  277. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  278. //{{AFX_MSG_MAP(CShellApp)
  279. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  280. // NOTE - the ClassWizard will add and remove mapping macros here.
  281. //    DO NOT EDIT what you see in these blocks of generated code!
  282. //}}AFX_MSG_MAP
  283. // Standard file based document commands
  284. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  285. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  286. // Standard print setup command
  287. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  288. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  289. END_MESSAGE_MAP()
  290. */
  291.  
  292. /////////////////////////////////////////////////////////////////////////////
  293. // CShellApp construction
  294.  
  295. CShellApp::CShellApp()
  296. {
  297.   // TODO: add construction code here,
  298.   // Place all significant initialization in InitInstance
  299. }
  300.  
  301. /////////////////////////////////////////////////////////////////////////////
  302. // The one and only CShellApp object
  303.  
  304. //CShellApp theApp;
  305.  
  306. /////////////////////////////////////////////////////////////////////////////
  307. // CShellApp initialization
  308.  
  309. UINT RunBackMirror( LPVOID pP ) {
  310.   CShellApp_app->init_lance();
  311.   return 0;
  312. }
  313.  
  314. BOOL LaunchMirror() {
  315.   WHTT_LOCK();
  316.   hts_resetvar();
  317.   WHTT_UNLOCK();
  318.   AfxBeginThread(RunBackMirror,NULL);
  319.   return 0;
  320. }
  321.  
  322. #if 0
  323. BOOL CShellApp::InitInstance()
  324. {
  325.   CShellApp_app=this;
  326.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  327.   
  328.   // Initialize OLE libraries
  329.   /*
  330.   if (!AfxOleInit())
  331.   {
  332.   AfxMessageBox(LANG(LANG_F1));
  333.   return FALSE;
  334.   }
  335.   AfxEnableControlContainer();
  336.   */
  337.   
  338.   // Fixer localisation dans la base de registre
  339.   //SetRegistryKey("WinHTTrack");
  340.   
  341.   // Standard initialization
  342.   // If you are not using these features and wish to reduce the size
  343.   //  of your final executable, you should remove from the following
  344.   //  the specific initialization routines you do not need.
  345.   /*
  346.   #ifdef _AFXDLL
  347.   Enable3dControls();            // Call this when using MFC in a shared DLL
  348.   #else
  349.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  350.   #endif
  351.   */
  352.   
  353.   // Register the application's document templates.  Document templates
  354.   //  serve as the connection between documents, frame windows and views.
  355.   
  356.   // Change the registry key under which our settings are stored.
  357.   // You should modify this string to be something appropriate
  358.   // such as the name of your company or organization.
  359.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  360.   
  361.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  362.   
  363.   // Register the application's document templates.  Document templates
  364.   //  serve as the connection between documents, frame windows and views.
  365.   
  366.   // Parse command line for standard shell commands, DDE, file open
  367.   /*CCommandLineInfo cmdInfo;
  368.   ParseCommandLine(cmdInfo);
  369.   */
  370.   
  371.   _Cinprogress_inst=NULL;
  372.   
  373.   LibRasUse=0;
  374.   
  375.   /*
  376.   #if USE_RAS
  377.   LibRas=new CDynamicRAS();
  378.   if (LibRas->IsRASLoaded()) 
  379.   LibRasUse=1;
  380.   else
  381.   LibRasUse=0;
  382.   #endif
  383.   */
  384.   
  385.   maintab = new CMainTab("WinHTTrack Website Copier");
  386.   
  387.   // PATCH-->
  388.   // ΘxΘcution..
  389.   init_lance();
  390.   
  391.   delete maintab;
  392.   maintab=NULL;
  393.   
  394.   // PATCH-->
  395.   /*
  396.   // Dispatch commands specified on the command line
  397.   if (!ProcessShellCommand(cmdInfo))
  398.         return FALSE;
  399.     
  400.       // The one and only window has been initialized, so show and update it.
  401.       m_pMainWnd->ShowWindow(SW_SHOW);
  402.       m_pMainWnd->UpdateWindow();
  403.   */  
  404.   
  405.   
  406.   return TRUE;
  407. }
  408. #endif
  409.  
  410. // PATCH-->
  411. // routines diverses
  412.  
  413. char* _SN(LLint n) {
  414.   static char str[256];
  415.   str[0]='\0';
  416.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  417.   return str;
  418. }
  419.  
  420. // t existe-t-il comme rΘpertoire?
  421. int dir_check(char* t) {
  422.   int dir;
  423.   FILE* fp=fopen(t,"rb");
  424.   dir=(errno==13);  // is directory
  425.   if (fp) fclose(fp);
  426.   return dir;
  427. }
  428.  
  429. void check_temp(char* t,char* s) {
  430.   if (strlen(s)==0)
  431.     if (dir_check(t))
  432.       strcpybuff(s,t);
  433. }
  434.  
  435.  
  436.  
  437. // PATCH-->
  438. // Routines gestion dials
  439. // PatchΘ pour 100% dials
  440.  
  441.  
  442. void CShellApp::init_lance() {
  443.   hts_init();
  444.   htswrap_add("check-link",httrackengine_check);
  445.   htswrap_add("init",httrackengine_init);
  446.   htswrap_add("free",httrackengine_uninit);
  447.   htswrap_add("start",httrackengine_start);
  448.   htswrap_add("end",httrackengine_end);
  449.   htswrap_add("check-html",httrackengine_htmlcheck);
  450.   htswrap_add("change-options",httrackengine_chopt);
  451.   htswrap_add("loop",httrackengine_loop);
  452.   htswrap_add("query",httrackengine_query);
  453.   htswrap_add("query2",httrackengine_query2);
  454.   htswrap_add("query3",httrackengine_query3);
  455.   htswrap_add("pause",httrackengine_pause);
  456.   
  457.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  458.   lance();             // Lancer miroir!
  459.   if (fp_debug) {
  460.     fprintf(fp_debug,"Building top index\r\n");
  461.     fflush(fp_debug);
  462.   }
  463.   Build_TopIndex();
  464. }
  465.  
  466. /* sauver profile */
  467. /* ask: demande confirmation, si cela vaut le coup */
  468. int Save_current_profile(int ask) {
  469.   CString winprofile;
  470.   if (ask) {
  471.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  472.       return IDNO;
  473.     int r;
  474.     char msg[256];
  475.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  476.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  477.       return r;
  478.   }
  479.   //
  480.   CWaitCursor wait;
  481.   
  482.   // sauver whtt
  483.   {
  484.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  485.     FILE* fp=fopen(st,"wb");
  486.     if (fp) fclose(fp);
  487.   }
  488.   
  489.   // sauver ini
  490.   winprofile=dialog0->GetPath();
  491.   if (winprofile.GetLength()>0)
  492.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  493.       winprofile+="\\";
  494.     winprofile+="hts-cache\\";
  495.     {
  496.       char tempo[HTS_URLMAXSIZE*2];
  497.       int i;
  498.       strcpybuff(tempo,winprofile);
  499.       for(i=0;i<(int)strlen(tempo);i++)
  500.         if (tempo[i]=='\\')
  501.           tempo[i]='/';              
  502.         structcheck(tempo);
  503.     }
  504.     
  505.     winprofile+="winprofile.ini";
  506.     Write_profile(winprofile,0);
  507.     
  508.     // marquer document comme "sauvΘ"
  509.     if (this_CSplitterFrame)
  510.       this_CSplitterFrame->SetSaved();
  511.     
  512.     return IDYES;
  513. }
  514.  
  515. // reprise possible?
  516. int check_continue(char* pathlog) {
  517.   char path_log[256];
  518.   strcpybuff(path_log,pathlog);
  519.   if (strlen(path_log)>0)
  520.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  521.       strcatbuff(path_log,"/");
  522.     if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  523.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prΘsent
  524.       return 1;
  525.       //}
  526.     }
  527.     if ((fexist(fconcat(path_log,"hts-cache/old.dat"))) && (fexist(fconcat(path_log,"hts-cache/old.ndx")))) {  // il existe dΘja un ancien cache prΘcΘdent.. renommer
  528.       return 1;
  529.     }
  530.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  531.     return 0;
  532. }
  533.  
  534.  
  535. void CShellApp::OptPannel() {
  536.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  537.   if (maintab->DoModal()==IDCANCEL) {
  538.     Read_profile("<mem>",0);      // restaurer
  539.   }
  540. }
  541.  
  542.  
  543. #define ADD_MIME_IN_COPT(A) \
  544.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  545.   strcatbuff(buff_MIME,"--assume "); \
  546.   strcatbuff(buff_MIME,maintab->m_option11.m_ext##A); \
  547.   strcatbuff(buff_MIME,"="); \
  548.   strcatbuff(buff_MIME,maintab->m_option11.m_mime##A); \
  549.   strcatbuff(buff_MIME," "); \
  550.   } \
  551.   
  552. // parser maintab et calculer options
  553. void compute_options() { 
  554.   CWaitCursor wait;
  555.   
  556.   /* Effacer options */
  557.   LINE[0]
  558.     =OPTIONurl[0]
  559.     =OPTIONfilelist[0]
  560.     =OPTIONproxy[0]
  561.     =OPTIONproxyftp[0]
  562.     =OPTIONport[0]
  563.     =OPTIONdepth[0]
  564.     =OPTIONextdepth[0]
  565.     =OPTIONget[0]
  566.     =OPTIONwhere[0]
  567.     =OPTIONmeth[0]
  568.     =OPTIONmaxfile[0]
  569.     =OPTIONmax[0]
  570.     =OPTIONfrag[0]
  571.     =OPTIONconn[0]
  572.     =OPTIONtog[0]
  573.     =OPTIONcache[0]
  574.     =OPTIONrobots[0]
  575.     =choixdeb[0]
  576.     =build[0]
  577.     =filtre[0]
  578.     =OPTIONindex[0]
  579.     =OPTIONindex2[0]
  580.     =OPTIONdos[0]
  581.     =OPTIONtime[0]
  582.     =OPTIONrate[0]
  583.     =OPTIONhostquit[0]
  584.     =OPTIONka[0]
  585.     =OPTIONuser[0]
  586.     =OPTIONfooter[0]
  587.     =OPTIONlog[0]
  588.     =OPTIONtestall[0]
  589.     =OPTIONparseall[0]
  590.     =OPTIONlink[0]
  591.     =OPTIONpath[0]
  592.     =OPTIONretry[0]
  593.     =OPTIONerrpage[0]
  594.     =OPTIONexternal[0]
  595.     =OPTIONnopurge[0]
  596.     =OPTIONhidepwd[0]
  597.     =OPTIONhidequery[0]
  598.     =OPTIONcookies[0]
  599.     =OPTIONchecktype[0]
  600.     =OPTIONparsejava[0]
  601.     =OPTIONCache2[0]
  602.     =OPTIONlogtype[0]
  603.     =OPTIONnorecatch[0]
  604.     =OPTIONtoler[0]
  605.     =OPTIONupdhack[0]
  606.     =OPTIONhttp10[0]
  607.     =OPTIONwaittime[0]
  608.     =OPTIONmaxtime[0]
  609.     =OPTIONmaxrate[0]
  610.     =OPTIONmaxconn[0]
  611.     =OPTIONmaxlinks[0]
  612.     =OPTIONhh[0]
  613.     =OPTIONmm[0]
  614.     =OPTIONss[0]
  615.     =buff_filtres[0]
  616.     =buff_MIME[0]
  617.     =OPTION_RasString[0]
  618.     ='\0';
  619.   /* Effacer options */
  620.   
  621.   // Mode de miroir
  622.   switch(dialog1->m_todo) {
  623.   case CB_ERR: case 0:
  624.     strcpybuff(choixdeb,"w");
  625.     break;
  626.   case 1:
  627.     strcpybuff(choixdeb,"W");
  628.     break;
  629.   case 2:
  630.     strcpybuff(choixdeb,"g");
  631.     break;
  632.   case 3:
  633.     strcpybuff(choixdeb,"Y");
  634.     break;
  635.   case 4:
  636.     strcpybuff(choixdeb,"!");
  637.     break;
  638.   default:
  639.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  640.       strcpybuff(choixdeb,"i");    // reprise
  641.     else
  642.       strcpybuff(choixdeb,"/");    // reprise cache prioritaire
  643.     break;
  644.   }
  645.   
  646.   // URLS
  647.   char trans[50000];
  648.   strcpybuff(trans,"");
  649.   strncatbuff(trans,dialog1->m_urls,30000);
  650.   strcpybuff(OPTIONurl,connversion(trans));
  651.   // --- formation du path
  652.   strcpybuff(OPTIONpath,"\""); strcatbuff(OPTIONpath,dialog0->GetPath0()); strcatbuff(OPTIONpath,"\"");
  653.   strcatbuff(OPTIONpath,",");
  654.   strcatbuff(OPTIONpath,"\""); strcatbuff(OPTIONpath,dialog0->GetPath0()); strcatbuff(OPTIONpath,"\"");
  655.   
  656.   // filelist
  657.   {
  658.     CString st=dialog1->m_filelist;
  659.     st.TrimLeft();
  660.     st.TrimRight();
  661.     strcpybuff(OPTIONfilelist,st);
  662.   }
  663.   
  664.   // stocker Θtat et hh/mm/ss
  665.   strcpybuff(OPTIONhh,dialog2->m_hh);
  666.   strcpybuff(OPTIONmm,dialog2->m_mm);
  667.   strcpybuff(OPTIONss,dialog2->m_ss);
  668.   if (strlen(OPTIONhh)) {    // heure
  669.     int x,y,z;
  670.     sscanf(OPTIONhh,"%d",&x);
  671.     x=min(max(x,0),23);
  672.     sprintf(OPTIONhh,"%d",x);
  673.     //
  674.     sscanf(OPTIONmm,"%d",&y);
  675.     y=min(max(y,0),59);
  676.     sprintf(OPTIONmm,"%d",y);
  677.     //
  678.     sscanf(OPTIONss,"%d",&z);
  679.     z=min(max(z,0),59);
  680.     sprintf(OPTIONss,"%d",z);
  681.     //
  682.     strcpybuff(OPTIONwaittime,"");
  683.     {
  684.       char str[32];
  685.       strcpybuff(OPTIONwaittime,"#u");
  686.       sprintf(str,"%d",x*3600+y*60+z);
  687.       strcatbuff(OPTIONwaittime,str);
  688.     }
  689.   }
  690.   strcpybuff(OPTION_RasString,dialog2->RasString);
  691.   OPTION_dial=dialog2->dial;
  692.   
  693.   if (choixdeb[0]=='/') {
  694.     strcpybuff(OPTIONcache,"C1");      // cache prio
  695.   } else {
  696.     if(!maintab->m_option3.m_cache) 
  697.       strcpybuff(OPTIONcache,"C0"); 
  698.     else 
  699.       strcpybuff(OPTIONcache,"C2");     // cache non prio 
  700.     //OPTIONcache[0]='\0'; 
  701.   }
  702.   
  703.   // ne pas recharger fichiers dΘja pris mais effacΘs
  704.   if(maintab->m_option9.m_norecatch) strcpybuff(OPTIONnorecatch,"%n"); else strcpybuff(OPTIONnorecatch,"");
  705.   
  706.   // proxy
  707.   strcpybuff(OPTIONproxy,maintab->m_option10.m_proxy);
  708.   strcpybuff(OPTIONport,maintab->m_option10.m_port);
  709.   if (maintab->m_option10.m_ftpprox) 
  710.     strcpybuff(OPTIONproxyftp, "%f");
  711.   else
  712.     strcpybuff(OPTIONproxyftp, "%f0");   
  713.   
  714.   //depth
  715.   strcpybuff(OPTIONdepth,maintab->m_option5.m_depth);
  716.   strcpybuff(OPTIONextdepth,maintab->m_option5.m_depth2);
  717.   
  718.   if(!maintab->m_option9.m_index) strcpybuff(OPTIONindex,"I0"); else OPTIONindex[0]='\0'; 
  719.   if(!maintab->m_option9.m_index2) strcpybuff(OPTIONindex2,"%I0"); else strcpybuff(OPTIONindex2,"%I"); 
  720.   if(maintab->m_option2.m_dos) 
  721.     strcpybuff(OPTIONdos,"L0"); 
  722.   else if(maintab->m_option2.m_iso9660) 
  723.     strcpybuff(OPTIONdos,"L2"); 
  724.   else 
  725.     OPTIONdos[0]='\0'; 
  726.   if(maintab->m_option1.m_testall) strcpybuff(OPTIONtestall,"t"); else OPTIONtestall[0]='\0'; 
  727.   if(maintab->m_option1.m_parseall) strcpybuff(OPTIONparseall,"%P"); else strcpybuff(OPTIONparseall,"%P0"); 
  728.   if(maintab->m_option1.m_link) strcpybuff(OPTIONlink,"n"); else OPTIONlink[0]='\0'; 
  729.   if(maintab->m_option1.m_htmlfirst) strcpybuff(OPTIONhtmlfirst,"p7"); else strcpybuff(OPTIONhtmlfirst,""); 
  730.   if(maintab->m_option2.m_errpage) strcpybuff(OPTIONerrpage,"o0"); else OPTIONerrpage[0]='\0'; 
  731.   if(maintab->m_option2.m_external) strcpybuff(OPTIONexternal,"x"); else OPTIONexternal[0]='\0'; 
  732.   if(maintab->m_option2.m_nopurge) strcpybuff(OPTIONnopurge,"X0"); else OPTIONnopurge[0]='\0'; 
  733.   if(maintab->m_option2.m_hidepwd) strcpybuff(OPTIONhidepwd,"%x"); else OPTIONhidepwd[0]='\0'; 
  734.   if(maintab->m_option2.m_hidequery) strcpybuff(OPTIONhidequery,"%q0"); else OPTIONhidequery[0]='\0'; 
  735.   
  736.   OPTIONrobots[0]='\0';
  737.   if(maintab->m_option8.m_robots==0) strcpybuff(OPTIONrobots,"s0"); 
  738.   else if(maintab->m_option8.m_robots==1) strcpybuff(OPTIONrobots,"s1"); 
  739.   else if(maintab->m_option8.m_robots==2) strcpybuff(OPTIONrobots,"s2"); 
  740.   
  741.   // cookies,checktype,parsejava
  742.   if(maintab->m_option8.m_cookies==0) strcpybuff(OPTIONcookies,"b0"); // else strcpybuff(OPTIONcookies,"b1");
  743.   if (maintab->m_option8.m_checktype>=0)
  744.     sprintf(OPTIONchecktype,"u%d",maintab->m_option8.m_checktype);
  745.   if(maintab->m_option8.m_parsejava==0) strcpybuff(OPTIONparsejava,"j0"); // else strcpybuff(OPTIONcookies,"j1");
  746.   if (maintab->m_option8.m_http10) strcpybuff(OPTIONhttp10,"%h");   // HTTP/1.0 notamment
  747.   if (maintab->m_option8.m_toler)  strcpybuff(OPTIONtoler,"%B");    // tolerent
  748.   if (maintab->m_option8.m_updhack)  strcpybuff(OPTIONupdhack,"%s");    // update hack
  749.   
  750.   // store all in cache,logtype
  751.   if(maintab->m_option9.m_Cache2!=0) strcpybuff(OPTIONCache2,"k");
  752.   if(maintab->m_option9.m_logtype==1) strcpybuff(OPTIONlogtype,"z");
  753.   else if(maintab->m_option9.m_logtype==2) strcpybuff(OPTIONlogtype,"Z");
  754.   if (maintab->m_option3.m_windebug) strcatbuff(OPTIONlogtype,"%H");      // debug headers
  755.   
  756.   strcpybuff(build,"");
  757.   if      (maintab->m_option2.m_build==0) strcpybuff(build,"N0");
  758.   else if (maintab->m_option2.m_build==1) strcpybuff(build,"N1");
  759.   else if (maintab->m_option2.m_build==2) strcpybuff(build,"N2");
  760.   else if (maintab->m_option2.m_build==3) strcpybuff(build,"N3");
  761.   else if (maintab->m_option2.m_build==4) strcpybuff(build,"N4");
  762.   else if (maintab->m_option2.m_build==5) strcpybuff(build,"N5");
  763.   else if (maintab->m_option2.m_build==6) strcpybuff(build,"N100");
  764.   else if (maintab->m_option2.m_build==7) strcpybuff(build,"N101");
  765.   else if (maintab->m_option2.m_build==8) strcpybuff(build,"N102");
  766.   else if (maintab->m_option2.m_build==9) strcpybuff(build,"N103");
  767.   else if (maintab->m_option2.m_build==10) strcpybuff(build,"N104");
  768.   else if (maintab->m_option2.m_build==11) strcpybuff(build,"N105");
  769.   else if (maintab->m_option2.m_build==12) strcpybuff(build,"N99");
  770.   else if (maintab->m_option2.m_build==13) strcpybuff(build,"N199");
  771.   else if (maintab->m_option2.m_build==14) {
  772.     strcpybuff(build,"-N \"");
  773.     strcatbuff(build,maintab->m_option2.Bopt.m_BuildString);
  774.     strcatbuff(build,"\"");
  775.   }
  776.   
  777.   strcpybuff(filtre,"");
  778.   if      (maintab->m_option3.m_filter==0) strcpybuff(filtre,"p0");
  779.   else if (maintab->m_option3.m_filter==1) strcpybuff(filtre,"p1");
  780.   else if (maintab->m_option3.m_filter==2) strcpybuff(filtre,"p2");
  781.   else if (maintab->m_option3.m_filter==3) {    /* default */
  782.     if(!maintab->m_option1.m_htmlfirst) strcpybuff(filtre,"p3");
  783.   }
  784.   else if (maintab->m_option3.m_filter==4) strcpybuff(filtre,"p7");
  785.   //
  786.   if      (maintab->m_option3.m_travel==0) strcatbuff(filtre,"S");
  787.   else if (maintab->m_option3.m_travel==1) strcatbuff(filtre,"D");
  788.   else if (maintab->m_option3.m_travel==2) strcatbuff(filtre,"U");
  789.   else if (maintab->m_option3.m_travel==3) strcatbuff(filtre,"B");
  790.   //
  791.   if      (maintab->m_option3.m_travel2==0) strcatbuff(filtre,"a");
  792.   else if (maintab->m_option3.m_travel2==1) strcatbuff(filtre,"d");
  793.   else if (maintab->m_option3.m_travel2==2) strcatbuff(filtre,"l");
  794.   else if (maintab->m_option3.m_travel2==3) strcatbuff(filtre,"e");
  795.   //
  796.   if      (maintab->m_option3.m_travel3==0) strcatbuff(filtre,"K0");
  797.   else if (maintab->m_option3.m_travel3==1) strcatbuff(filtre,"K");
  798.   else if (maintab->m_option3.m_travel3==2) strcatbuff(filtre,"K3");
  799.   else if (maintab->m_option3.m_travel3==3) strcatbuff(filtre,"K4");
  800.  
  801.   if (maintab->m_option9.m_logf) strcpybuff(OPTIONlog,"f2"); else strcpybuff(OPTIONlog,"Q"); 
  802.   
  803.   if(maintab->m_option5.m_sizemax!=""){
  804.     strcpybuff(OPTIONmax,"M");
  805.     strcatbuff(OPTIONmax,maintab->m_option5.m_sizemax);
  806.   } else strcpybuff(OPTIONmax,"");
  807.   
  808.   if(maintab->m_option5.m_pausebytes!=""){
  809.     strcpybuff(OPTIONfrag,"G");
  810.     strcatbuff(OPTIONfrag,maintab->m_option5.m_pausebytes);
  811.   } else strcpybuff(OPTIONfrag,"");
  812.   
  813.   
  814.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  815.     strcpybuff(OPTIONmaxfile,"m");
  816.     if(maintab->m_option5.m_othermax!="") strcatbuff(OPTIONmaxfile,maintab->m_option5.m_othermax);
  817.     else strcatbuff(OPTIONmaxfile,"0");
  818.     if(maintab->m_option5.m_maxhtml!="") {strcatbuff(OPTIONmaxfile,",");strcatbuff(OPTIONmaxfile,maintab->m_option5.m_maxhtml);}
  819.     else {strcatbuff(OPTIONmaxfile,",");strcatbuff(OPTIONmaxfile,"0");}
  820.   } else strcpybuff(OPTIONmaxfile,"");
  821.   
  822.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  823.     strcpybuff(OPTIONconn,"c");
  824.     strcatbuff(OPTIONconn,maintab->m_option4.m_connexion);
  825.   } else strcpybuff(OPTIONconn,"");
  826.   
  827.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  828.     strcpybuff(OPTIONtime,"T");
  829.     strcatbuff(OPTIONtime,maintab->m_option4.m_timeout);
  830.   } else strcpybuff(OPTIONtime,"");
  831.   
  832.   // quitter host si timeout ou rate out
  833.   strcpybuff(OPTIONhostquit,"");
  834.   {
  835.     int a=0;
  836.     if (maintab->m_option4.m_remt)
  837.       a+=1;
  838.     if (maintab->m_option4.m_rems)
  839.       a+=2;
  840.     sprintf(OPTIONhostquit,"H%d",a);
  841.   }
  842.  
  843.   // Keep-Alive
  844.   if (maintab->m_option4.m_ka) {
  845.     strcpybuff(OPTIONka, "%k");
  846.   } else {
  847.     strcpybuff(OPTIONka, "%k0");
  848.   }
  849.  
  850.   
  851.   //--> max time
  852.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  853.     strcpybuff(OPTIONmaxtime,"E");
  854.     strcatbuff(OPTIONmaxtime,maintab->m_option5.m_maxtime);
  855.   } else strcpybuff(OPTIONmaxtime,"");
  856.   
  857.   //--> max rate
  858.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  859.     strcpybuff(OPTIONmaxrate,"A");
  860.     strcatbuff(OPTIONmaxrate,maintab->m_option5.m_maxrate);
  861.   } else strcpybuff(OPTIONmaxrate,"");
  862.   
  863.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  864.     strcpybuff(OPTIONmaxconn,"%c");
  865.     strcatbuff(OPTIONmaxconn,maintab->m_option5.m_maxconn);
  866.   } else strcpybuff(OPTIONmaxconn,"");
  867.   
  868.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  869.     strcpybuff(OPTIONmaxlinks,"#L");
  870.     strcatbuff(OPTIONmaxlinks,maintab->m_option5.m_maxlinks);
  871.   } else strcpybuff(OPTIONmaxlinks,"");
  872.   
  873.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  874.     strcpybuff(OPTIONrate,"J");
  875.     strcatbuff(OPTIONrate,maintab->m_option4.m_rate);
  876.   } else strcpybuff(OPTIONrate,"");
  877.   
  878.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  879.     strcpybuff(OPTIONuser,"\"");
  880.     strcatbuff(OPTIONuser,maintab->m_option6.m_user);
  881.     strcatbuff(OPTIONuser,"\"");
  882.   } else strcpybuff(OPTIONuser,"");
  883.   
  884.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  885.     strcpybuff(OPTIONfooter,"\"");
  886.     strcatbuff(OPTIONfooter,maintab->m_option6.m_footer);
  887.     strcatbuff(OPTIONfooter,"\"");
  888.   } else strcpybuff(OPTIONfooter,"");
  889.   
  890.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  891.     strcpybuff(OPTIONretry,"R");
  892.     strcatbuff(OPTIONretry,maintab->m_option4.m_retry);
  893.   } else strcpybuff(OPTIONretry,"");
  894.   
  895.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  896.     strcpybuff(buff_filtres,maintab->m_option7.m_url2);
  897.   } else strcpybuff(buff_filtres,"");
  898.   
  899.   
  900.   // MIME
  901.   buff_MIME[0]='\0';
  902.   ADD_MIME_IN_COPT(1)
  903.     ADD_MIME_IN_COPT(2)
  904.     ADD_MIME_IN_COPT(3)
  905.     ADD_MIME_IN_COPT(4)
  906.     ADD_MIME_IN_COPT(5)
  907.     ADD_MIME_IN_COPT(6)
  908.     ADD_MIME_IN_COPT(7)
  909.     ADD_MIME_IN_COPT(8)
  910.     
  911.     /* autres options: RAS */
  912.     if (dialog2->m_rasdisc)
  913.       disconnect=1;     /* dΘconnexion α la fin */
  914.     else
  915.       disconnect=0;
  916. }
  917.  
  918. // Les routines α dΘfinir:
  919. int __cdecl httrackengine_check(char* adr,char* fil,int status) {  // appelΘ par le wizard
  920.   return -1;
  921. }
  922. void __cdecl httrackengine_init() {    // appelΘ lors de l'init de HTTRACK, avant le dΘbut d'un miroir
  923. #if USE_RAS
  924.   has_started=0;
  925. #endif
  926.   httrackengine_loop(NULL,0,0,0,0,NULL,0);  // init
  927.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  928. }
  929. void __cdecl httrackengine_uninit() {  // appelΘ en fin de miroir (peut Ωtre utile!!!)
  930. #if USE_RAS
  931.   if (LibRasUse) {        /* librairie RAS chargΘe */
  932.     if (disconnect) {     /* on doit dΘconnecter */
  933.       if (connected) {    /* on a initiΘ une connexion */
  934.         if (conn)
  935.           LibRas->RasHangUp(conn);
  936.       } else {            /* tout dΘconnecter */
  937.         // On coupe tout (non, pas bourrin)
  938.         DWORD size;
  939.         RASCONN* adr;
  940.         int count=256;
  941.         size = sizeof(RASCONN)*(count+2);
  942.         adr = (RASCONN*) (char*) calloc(size,1);
  943.         if (adr) {
  944.           DWORD ent;
  945.           int i;
  946.           for(i=0;i<count;i++) {
  947.             adr[i].dwSize=sizeof(RASCONN);
  948.             strcpybuff(adr[i].szEntryName,"");
  949.           }
  950.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  951.             for(i=0;i<(int)ent;i++) {
  952.               LibRas->RasHangUp(adr[i].hrasconn);
  953.             }
  954.           }
  955.           free(adr);
  956.         }
  957.         
  958.       }
  959.     }
  960.   }
  961. #endif
  962. }
  963. int __cdecl httrackengine_start(void* dummy) {   // appelΘ lors du dΘmarrage du miroir (premiΦres requΦtes)
  964. #if USE_RAS
  965.   // connexion RAS
  966.   has_started=1;    // dΘmarrage
  967.   connected=0;
  968.   conn = NULL;
  969.   memset(&SInfo, 0, sizeof(SInfo));
  970.   if (LibRasUse) {
  971.     if (strlen(OPTION_RasString)>0) {    // sΘlection provider
  972.       if (!LibRas->RasDial(NULL,NULL,&OPTION_dial,NULL,NULL,&conn)) {
  973.         RASCONNSTATUS status;
  974.         do {
  975.           status.dwSize = sizeof(status);
  976.           LibRas->RasGetConnectStatus(conn,&status);
  977.           switch(status.rasconnstate) {
  978.           case RASCS_Connected : 
  979.             connected=1;
  980.             break;
  981.           case RASCS_Disconnected :
  982.             strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  983.             connected=-1;
  984.             break;
  985.           }
  986.         } while(connected==0);
  987.       } else {
  988.         strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Θtablir la connexion"*/));
  989.         connected=-1;
  990.         //termine=1;
  991.       }
  992.     }
  993.     //
  994.     if (connected != -1)  // si pas d'erreur RAS
  995.       return 1;
  996.     else
  997.       return 0;
  998.   } else
  999.     return 1;
  1000. #else
  1001.   return 1;
  1002. #endif
  1003. }
  1004. int  httrackengine_end() {     // appelΘ lors de la fin du miroir (plus de liens α charger)
  1005.   WHTT_LOCK();
  1006.   termine=1;
  1007.   if (_Cinprogress_inst) {
  1008.     _Cinprogress_inst->EndDialog(IDOK);
  1009.     _Cinprogress_inst=NULL;
  1010.   }
  1011.   WHTT_UNLOCK();
  1012.   return 1;
  1013. }
  1014. int __cdecl httrackengine_htmlcheck(char* html,int len,char* url_adresse,char* url_fichier) {    // appelΘ α chaque fois qu'un html doit Ωtre scannΘ (utile pour la prospection mais inutile ici)
  1015.   return 1;
  1016. }
  1017. int __cdecl httrackengine_chopt(void* opt) {
  1018.   return 1;
  1019. }
  1020.  
  1021. // Le routine la plus utile sans doute: elle refresh les tableaux
  1022. // C'est la 2e routine en thread qui assure le refresh graphique
  1023. // (plus efficace)
  1024. // -->C'est elle qui dΘcide de tout arrΩter si elle dΘtecte in termine_request<--
  1025. int __cdecl httrackengine_loop(
  1026.                                void* _back,int back_max,int back_index,
  1027.                                int lien_n,int lien_tot,
  1028.                                int stat_time,
  1029.                                hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  1030.   static char s[HTS_URLMAXSIZE*2]="";  // utilisΘ plus loin
  1031.   int stat_written=-1;
  1032.   int stat_updated=-1;
  1033.   int stat_errors=-1;
  1034.   int stat_warnings=-1;
  1035.   int stat_infos=-1;
  1036.   int nbk=-1;
  1037.   LLint nb=-1;
  1038.   int stat_nsocket=-1;
  1039.   LLint stat_bytes=-1;
  1040.   LLint stat_bytes_recv=-1;
  1041.   int irate=-1;
  1042.   
  1043.   WHTT_LOCK();
  1044.  
  1045.   if (stats) {
  1046.     stat_written=stats->stat_files;
  1047.     stat_updated=stats->stat_updated_files;
  1048.     stat_errors=stats->stat_errors;
  1049.     stat_warnings=stats->stat_warnings;
  1050.     stat_infos=stats->stat_infos;
  1051.     nbk=stats->nbk;
  1052.     stat_nsocket=stats->stat_nsocket;
  1053.     irate=(int)stats->rate;
  1054.     nb=stats->nb;
  1055.     stat_bytes=stats->nb;
  1056.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  1057.   }
  1058.   
  1059. #if !SHELL_MULTITHREAD
  1060.   static TStamp last_time;
  1061. #endif
  1062.   int rate;
  1063.   // casts
  1064.   lien_back* back=(lien_back*) _back;
  1065.   //  static int ft=-1;
  1066.   
  1067.   if (back_max == 0) {
  1068. #if !SHELL_MULTITHREAD
  1069.     last_time=0;
  1070. #endif
  1071.     // en cas de manque de time
  1072.     SInfo.refresh=1;
  1073.     SInfo.stat_timestart=time_local();
  1074.     WHTT_UNLOCK();
  1075.     return 1;
  1076.   }
  1077.   
  1078.   if ((termine) || (termine_requested)) {
  1079.     SInfo.refresh=0;      // pas de refresh
  1080.     SInfo.refresh=0;      // pas de refresh
  1081.     termine_requested=1;
  1082.     WHTT_UNLOCK();
  1083.     return 0;
  1084.   }
  1085.   
  1086.   if (stat_written>=0) SInfo.stat_written=stat_written;
  1087.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  1088.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  1089.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  1090.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  1091.   
  1092. #if SHELL_MULTITHREAD 
  1093.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  1094.   if (SInfo.ask_refresh) {
  1095. #else
  1096.     TStamp tl=0;
  1097.     {
  1098.       time_t tt;
  1099.       struct tm* A;
  1100.       tt=time(NULL);
  1101.       A=localtime(&tt);
  1102.       tl+=A->tm_sec;
  1103.       tl+=A->tm_min*60;
  1104.       tl+=A->tm_hour*60*60;
  1105.       //tl+=A->tm_yday*60*60*24;
  1106.       //tl+=A->tm_year*60*60*24*365;
  1107.       
  1108.       tl*=1000;  // en ms
  1109.       
  1110.       struct _timeb timebuffer;
  1111.       char *timeline;
  1112.       _ftime( &timebuffer );
  1113.       timeline = ctime( & ( timebuffer.time ) );
  1114.       
  1115.       tl+=timebuffer.millitm;    // + ms
  1116.     }
  1117.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1118.       last_time=tl;
  1119. #endif
  1120.       //INFILLMEM_LOCKED=1;    // locker interface
  1121.       // OPTI int rate;
  1122.       SInfo.ask_refresh=0;
  1123.       
  1124.       // pour Θviter temps cpu consommΘ trop grand
  1125.       // Sleep(10);
  1126.       
  1127.       // initialiser ft
  1128.       if ((stat_nsocket==-1)) {
  1129.         if (SInfo.ft==-1) {
  1130.           SInfo.ft=stat_time;
  1131.         }
  1132.       }
  1133.       
  1134. #if !SHELL_MULTITHREAD
  1135.       //
  1136.       MSG msg;  
  1137.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1138.         switch (msg.message) {
  1139.         case WM_COMMAND:        
  1140.           switch(msg.wParam) { 
  1141.           case ID_APP_ABOUT: {
  1142.             Cabout about;
  1143.             about.DoModal();                                    }
  1144.             break;
  1145.           case ID_APP_EXIT: case WM_CLOSE :
  1146.             termine_requested=1;
  1147.             break;
  1148.           case  WM_DESTROY: case WM_NCDESTROY: 
  1149.             termine_requested=1;
  1150.             break;
  1151.           }
  1152.           break;        
  1153.           default:
  1154.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1155.             break;
  1156.         }
  1157.       }
  1158.       //
  1159. #endif
  1160.       
  1161.       // calculer heure si ce n'est dΘja fait
  1162.       if (stat_time<0)
  1163.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1164.       
  1165.       // calculer transfer rate
  1166.       if ((stat_time>0) && (stat_bytes_recv>0))
  1167.         rate=(int)(stat_bytes_recv/stat_time);
  1168.       else
  1169.         rate=0;    // pas d'infos
  1170.       
  1171.       // stocker infos: octets transfΘrΘs, temps, etc.
  1172.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1173.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1174.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1175.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1176.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1177.       if (rate>0)  SInfo.rate=rate;                // rate
  1178.       if (irate>=0) SInfo.irate=irate;             // irate
  1179.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1180.       if (SInfo.stat_back>=0) SInfo.stat_back=nbk;
  1181.       
  1182.       // back: tableau de back_max ΘlΘments de cache
  1183.       // back_max: nombre d'ΘlΘments ^^^^
  1184.       // lien_tot: nombre total de liens traitΘs pour le moment
  1185.       // stat_bytes: octets sauvegardΘs
  1186.       // stat_bytes_recv: octets tΘlΘchargΘs
  1187.       // stat_time: temps en seconde depuis le dΘbut du miroir
  1188.       // stat_nsocket: nombre de sockets connectΘes actuellement
  1189.       // on peut en dΘduire rate=stat_bytes_recv/stat_time
  1190.       
  1191.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1192.       
  1193.       // parcourir registre des liens
  1194.       if (back_index>=0) {  // seulement si index passΘ
  1195.         int j,k;
  1196.         int index=0;
  1197.         int ok=0;         // idem
  1198.         int l;            // idem
  1199.         int M=32;         // idem
  1200.         
  1201.         StatsBufferback=(void*) back;
  1202.         StatsBufferback_max=back_max;
  1203.         {
  1204.           int i;
  1205.           for(i=0;i<NStatsBuffer;i++) {
  1206.             strcpybuff(StatsBuffer[i].etat,"");
  1207.             strcpybuff(StatsBuffer[i].nom,"");
  1208.             strcpybuff(StatsBuffer[i].fichier,"");
  1209.             strcpybuff(StatsBuffer[i].url_sav,"");
  1210.             StatsBuffer[i].back=NULL;
  1211.             StatsBuffer[i].size=0;
  1212.             StatsBuffer[i].sizetot=0;
  1213.           }
  1214.         }
  1215.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1216.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  1217.             int _i;
  1218.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1219.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1220.               if (back[i].status>=0) {     // signifie "lien actif"
  1221.                 // int ok=0;  // OPTI
  1222.                 ok=0;
  1223.                 switch(j) {
  1224.                 case 0:     // prioritaire
  1225.                   if ((back[i].status>0) && (back[i].status<99)) {
  1226.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rΘception"*/)); ok=1;
  1227.                   }
  1228.                   break;
  1229.                 case 1:
  1230.                   if (back[i].status==99) {
  1231.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requΦte"*/)); ok=1;
  1232.                   }
  1233.                   else if (back[i].status==100) {
  1234.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1235.                   }
  1236.                   else if (back[i].status==101) {
  1237.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1238.                   }
  1239.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1240.                     sprintf(StatsBuffer[index].etat,"ftp: %s",back[i].info); ok=1;
  1241.                   }
  1242.                   else if (back[i].status==102) {         // SSL handshake
  1243.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1244.                   }
  1245.                   else if (back[i].status==-103) {         // waiting (keep-alive)
  1246.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8)); ok=1;
  1247.                   }
  1248.                   break;
  1249.                 default:
  1250.                   if (back[i].status==0) {  // prΩt
  1251.                     if ((back[i].r.statuscode==200)) {
  1252.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prΩt"*/)); ok=1;
  1253.                     }
  1254.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1255.                       char tempo[256]; tempo[0]='\0';
  1256.                       infostatuscode(tempo,back[i].r.statuscode);
  1257.                       strcpybuff(StatsBuffer[index].etat,tempo); ok=1;
  1258.                     }
  1259.                     else {
  1260.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1261.                     }
  1262.                   }
  1263.                   break;
  1264.                 }
  1265.                 
  1266.                 if (ok) {
  1267.                   // OPTI int l;
  1268.                   // OPTI int M=32;     // longueur
  1269.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1270.                   //
  1271.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1272.                   //
  1273.                   s[0]='\0';
  1274.                   strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1275.                   if (strcmp(back[i].url_adr,"file://"))
  1276.                     strcatbuff(s,back[i].url_adr);
  1277.                   else
  1278.                     strcatbuff(s,"localhost");
  1279.                   if (back[i].url_fil[0]!='/')
  1280.                     strcatbuff(s,"/");
  1281.                   strcatbuff(s,back[i].url_fil);
  1282.                   
  1283.                   StatsBuffer[index].fichier[0]='\0';
  1284.                   {
  1285.                     char* a=strrchr(s,'/');
  1286.                     if (a) {
  1287.                       strncatbuff(StatsBuffer[index].fichier,a,200);
  1288.                       *a='\0';
  1289.                     }
  1290.                   }
  1291.                   
  1292.                   if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  1293.                     strcpybuff(StatsBuffer[index].nom,s);
  1294.                   else {
  1295.                     // couper
  1296.                     StatsBuffer[index].nom[0]='\0';
  1297.                     strncatbuff(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1298.                     strcatbuff(StatsBuffer[index].nom,"...");
  1299.                     strcatbuff(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1300.                   }
  1301.                   
  1302.                   //if (back[i].url_fil[0]!='/') printf("/");
  1303.                   
  1304.                   if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  1305.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1306.                     StatsBuffer[index].size=back[i].r.size;
  1307.                   } else {  // pas de taille prΘdΘfinie
  1308.                     if (back[i].status==0) {  // prΩt
  1309.                       StatsBuffer[index].sizetot=back[i].r.size;
  1310.                       StatsBuffer[index].size=back[i].r.size;
  1311.                     } else {
  1312.                       StatsBuffer[index].sizetot=8192;
  1313.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1314.                     }
  1315.                   }
  1316.                   index++;
  1317.                 }
  1318.               }
  1319.             }
  1320.           }
  1321.         }
  1322.     }
  1323.     
  1324. #if SHELL_MULTITHREAD
  1325.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1326. #else
  1327.     inprogress_refresh();  // tout de suite (non multithread)
  1328. #endif
  1329.     // INFILLMEM_LOCKED=0;    // dΘlocker interface
  1330.   }
  1331.   WHTT_UNLOCK();
  1332.   return (termine==0);
  1333. }
  1334.  
  1335. int inprogress_refresh() {
  1336.   static int toggle=0;
  1337.   // WHTT_LOCK(); // deja fait
  1338.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1339.     if (SInfo.refresh) {
  1340.       // INREDRAW_LOCKED=1;
  1341.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1342.       int icn;
  1343.       icn=inprogress->IsIconic();
  1344.       CString lnk;
  1345.       if (SInfo.stat_back)
  1346.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1347.       else
  1348.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1349.       if (!icn) {
  1350.         int parsing=0;
  1351.         if (!soft_term_requested) {
  1352.           if (!hts_setpause(-1)) {
  1353.             if (!(parsing=hts_is_parsing(-1)))
  1354.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RΘception des fichiers"*/)); 
  1355.             else {
  1356.               switch(hts_is_testing()) {
  1357.               case 0:
  1358.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1359.                 break;
  1360.               case 1:
  1361.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1362.                 break;
  1363.               case 2:
  1364.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11b)); 
  1365.                 break;
  1366.               case 3:
  1367.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11c)); 
  1368.                 break;
  1369.               }
  1370.             }
  1371.           } else {
  1372.             if (((toggle++)/5)%2)
  1373.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1374.             else
  1375.               inprogress->SetDlgItemText(IDC_inforun,"");
  1376.           }
  1377.         } else {
  1378.           if (((toggle++)/5)%2)
  1379.             inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13b));
  1380.           else
  1381.             inprogress->SetDlgItemText(IDC_inforun,"");
  1382.         }
  1383.         
  1384.         if (SInfo.stat_time>0) {
  1385.           char s[256];
  1386.           qsec2str(s,(TStamp) SInfo.stat_time);
  1387.           inprogress->SetDlgItemText(IDC_i1 ,s);  // time
  1388.         } else
  1389.           inprogress->SetDlgItemText(IDC_i1 , _SN(SInfo.stat_time) );  // time
  1390.         inprogress->SetDlgItemText(IDC_i0 , int2bytes(SInfo.stat_bytes) );  // bytes
  1391.         inprogress->SetDlgItemText(IDC_i2 , lnk);  // scanned
  1392.         if (SInfo.stat_nsocket>0)
  1393.           inprogress->SetDlgItemText(IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1394.         else
  1395.           inprogress->SetDlgItemText(IDC_i3 , "none" );  // wait
  1396.         
  1397.         CString st;
  1398.         st.Format("%s (%s)",int2bytessec(SInfo.irate),int2bytessec(SInfo.rate));
  1399.         inprogress->SetDlgItemText(IDC_i4 , st );  // rate
  1400.         
  1401.         inprogress->SetDlgItemText(IDC_i5 , _SN(SInfo.stat_errors) );
  1402.         inprogress->SetDlgItemText(IDC_i6 , _SN(SInfo.stat_written) );
  1403.         {
  1404.           char tempo[256];
  1405.           int pc=0;
  1406.           if (SInfo.stat_written)
  1407.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1408.           if (pc)
  1409.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1410.           else
  1411.             sprintf(tempo,"%d",SInfo.stat_updated);
  1412.           inprogress->SetDlgItemText(IDC_i7 , tempo );
  1413.         }
  1414.         
  1415.         /*if (!parsing)*/
  1416.         {
  1417.           {
  1418.             int i;
  1419.             for(i=0;i<NStatsBuffer;i++) {
  1420.               if (StatsBuffer[i].sizetot>0) {
  1421.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1422.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1423.                 StatsBuffer[i].offset = (int) d;
  1424.               } else
  1425.                 StatsBuffer[i].offset = 0;
  1426.             }
  1427.           }
  1428.           
  1429.           if (!parsing)
  1430.             inprogress->m_sl0.SetRange(0,1000);
  1431.           inprogress->m_sl1.SetRange(0,1000);
  1432.           inprogress->m_sl2.SetRange(0,1000);
  1433.           inprogress->m_sl3.SetRange(0,1000);
  1434.           inprogress->m_sl4.SetRange(0,1000);
  1435.           inprogress->m_sl5.SetRange(0,1000);
  1436.           inprogress->m_sl6.SetRange(0,1000);
  1437.           inprogress->m_sl7.SetRange(0,1000);
  1438.           inprogress->m_sl8.SetRange(0,1000);
  1439.           inprogress->m_sl9.SetRange(0,1000);
  1440.           inprogress->m_sl10.SetRange(0,1000);
  1441.           inprogress->m_sl11.SetRange(0,1000);
  1442.           inprogress->m_sl12.SetRange(0,1000);
  1443.           inprogress->m_sl13.SetRange(0,1000);
  1444.           
  1445.           if (!parsing)
  1446.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1447.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1448.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1449.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1450.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1451.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1452.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1453.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1454.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1455.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1456.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1457.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1458.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1459.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1460.           
  1461.           // redraw en boucle
  1462.           {
  1463.             int i=0;
  1464.             if (parsing)
  1465.               i++;
  1466.             for( ; i<NStatsBuffer;i++) {
  1467.               CString st;
  1468.               st = StatsBuffer[i].etat;
  1469.               st.Replace("&", "&&");
  1470.               inprogress->element[0][i]->SetWindowText(st);
  1471.               st = StatsBuffer[i].nom;
  1472.               st.Replace("&", "&&");
  1473.               inprogress->element[1][i]->SetWindowText(st);
  1474.               st = StatsBuffer[i].fichier;
  1475.               st.Replace("&", "&&");
  1476.               inprogress->element[4][i]->SetWindowText(st);
  1477.               
  1478.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1479.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1480.                 if (!StatsBuffer[i].actived)
  1481.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1482.                 else
  1483.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1484.                 inprogress->element[3][i]->RedrawWindow();
  1485.               }
  1486.             }
  1487.           }
  1488.           //
  1489.         }
  1490.         /* else*/
  1491.         if (parsing) {  // parsing
  1492.           //
  1493.           inprogress->m_sl0.SetRange(0,100);
  1494.           inprogress->m_sl0.SetPos(parsing);
  1495.           inprogress->element[0][0]->SetWindowText(LANG(LANG_F14 /*"scanning","parcours"*/));
  1496.           inprogress->element[1][0]->SetWindowText(StatsBuffer[0].nom);
  1497.           inprogress->element[4][0]->SetWindowText("");
  1498.           //inprogress->element[0][1]->SetWindowText();
  1499.         }
  1500.         
  1501.       }
  1502.       {
  1503.         static char last_info[256]="";
  1504.         char info[256];
  1505.         if ((SInfo.stat_nsocket==-1)) {
  1506. #if USE_RAS
  1507.           if (!has_started)
  1508. #endif
  1509.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmΘe pour dΘmarrer"*/));
  1510. #if USE_RAS
  1511.           else
  1512.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1513. #endif
  1514.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1515.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1516.           // inprogress->SetDlgItemText(IDC_nm1,_SN(ft));
  1517.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisΘe mais pas en icone
  1518.             sprintf(info,"[%d s]",SInfo.stat_time);
  1519.           } else {
  1520.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1521.           }
  1522.         } else {
  1523.           if (icn) {  // minimisΘe
  1524.             sprintf(info,"[%s]",lnk);
  1525.           } else {
  1526.             char byteb[256];
  1527.             sprintf(byteb, LLintP, SInfo.stat_bytes);
  1528.             sprintf(info,LANG(LANG_F18),lnk,byteb);
  1529.           }
  1530.         }
  1531.         if (strcmp(info,last_info)) {       /* a changΘ */
  1532.           strcpybuff(last_info,info);           /* recopier */
  1533.           if (this_CSplitterFrame->iconifie)  // minimisΘ icone
  1534.             this_CSplitterFrame->IconChange(last_info);
  1535.           else
  1536.             this_app->GetMainWnd()->SetWindowText(last_info);
  1537.         }
  1538.       }  
  1539.       
  1540.       //inprogress->UpdateWindow();
  1541.     } else {
  1542.     }
  1543.   }
  1544.   // WHTT_UNLOCK();
  1545.   return 1;
  1546. }
  1547.  
  1548. /*
  1549. // refresh scan
  1550. int inprogress_refresh_scan() {
  1551. if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1552. if (!SInfo.refresh) {
  1553. if (!inprogress->IsIconic()) {
  1554. int n;
  1555. // patch pour le scanning
  1556. if (n=hts_is_parsing()) {
  1557. strcpybuff(StatsBuffer[0].etat,"scanning");
  1558. inprogress->element[0][0]->SetWindowText("scanning");
  1559. StatsBuffer[0].sizetot=100;
  1560. StatsBuffer[0].size=n;
  1561. inprogress->m_sl0.SetRange(0,100);  // progression en % du scanning
  1562. inprogress->m_sl0.SetPos(n);
  1563. //} else {
  1564. //  inprogress->element[0][0]->SetWindowText("...");
  1565. }
  1566. }
  1567. }
  1568. }
  1569. return 1;
  1570. }
  1571. */
  1572.  
  1573. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1574. char* __cdecl httrackengine_query(char* question) {
  1575.   strcpybuff(WIZ_question,question);
  1576.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1577.   return WIZ_reponse;
  1578. }
  1579.  
  1580. char* __cdecl httrackengine_query2(char* question) {
  1581.   strcpybuff(WIZ_question,question);
  1582.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1583.   return WIZ_reponse;
  1584. }
  1585.  
  1586. char* __cdecl httrackengine_query3(char* question) {
  1587.   strcpybuff(WIZ_question,question);
  1588.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1589.   return WIZ_reponse;
  1590. }
  1591.  
  1592. void __cdecl httrackengine_pause(char* lockfile) {
  1593.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1594.   remove(lockfile);
  1595. }
  1596.  
  1597. // modif RX 10/10/98 pour gestion des , et des tabs
  1598. char* connversion(char* chaine)
  1599. {
  1600.   for(int i=0;i < (int) strlen(chaine);i++) 
  1601.     if(chaine[i]=='\n') chaine[i]=' ';
  1602.     else if(chaine[i]==13) chaine[i]=' ';
  1603.     else if(chaine[i]==9) chaine[i]=' ';
  1604.     /*else if(chaine[i]==',') chaine[i]=' ';*/
  1605.     
  1606.     return chaine;
  1607. }
  1608.  
  1609.  
  1610. #if SHELL_MULTITHREAD
  1611. void __cdecl RunBackRobot(void* al_p) {
  1612.   int argc;
  1613.   char** argv;
  1614.   
  1615.   while((!inprogress) && (!termine)) Sleep(10);
  1616.   if (inprogress)
  1617.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1618.     //Sleep(100);
  1619.     
  1620.     Robot_params* al=(Robot_params*) al_p;
  1621.     argc = al->argc;
  1622.     argv = al->argv;
  1623.     /* launch the engine */
  1624.     hts_init();
  1625.     HTTRACK_result=hts_main(argc,argv);
  1626.     /* clear all vars */
  1627.     WHTT_LOCK();
  1628.     termine=1;
  1629.     WHTT_UNLOCK();
  1630.     hts_uninit();
  1631.     
  1632.     _endthread();
  1633. }
  1634. #endif
  1635.  
  1636. // modifs RX 10/10/98: gestion des ,
  1637. CString change(char* chaine,char c) {
  1638.   int comma=1; int first=1;
  1639.   CString chaine1;
  1640.   for(int i=0;i < (int) strlen(chaine);i++) {
  1641.     switch(chaine[i]) {
  1642.     case 10: case 13: case 9: case ' ': case ',':
  1643.       comma=1; 
  1644.       break;
  1645.     default:
  1646.       if (comma) {
  1647.         if (!first) chaine1 +=' ';
  1648.         else first=0; 
  1649.         chaine1  +=c; 
  1650.         comma=0;
  1651.       }
  1652.       chaine1 += chaine[i]; 
  1653.       break;
  1654.     }
  1655.   }
  1656.   return chaine1;
  1657. }
  1658.  
  1659.  
  1660. // Lancement
  1661. void lance(void) {
  1662.   char *argv[1999];
  1663.   int argc=1;
  1664.   int g=0;
  1665.   int i =0;
  1666.   
  1667.   //
  1668.   if (fp_debug) {
  1669.     fprintf(fp_debug,"Building command line\r\n");
  1670.     fflush(fp_debug);
  1671.   }
  1672.   //
  1673.   LINE[0]='\0';
  1674.   strcpybuff(LINE,"-");
  1675.   if (choixdeb[0]!='W')
  1676.     strcatbuff(LINE,"q");         // quiet
  1677.   
  1678.   if (choixdeb[0]=='/')
  1679.     strcatbuff(LINE,"i");
  1680.   else if (choixdeb[0]!='!')
  1681.     strcatbuff(LINE,choixdeb);
  1682.   // option de profondeur
  1683.   if(strcmp(OPTIONdepth,"")!=0) { 
  1684.     strcatbuff(LINE,"r");
  1685.     strcatbuff(LINE,OPTIONdepth);
  1686.   }
  1687.   if(strcmp(OPTIONextdepth,"")!=0) { 
  1688.     strcatbuff(LINE,"%e");
  1689.     strcatbuff(LINE,OPTIONextdepth);
  1690.   }
  1691.   if(strcmp(OPTIONcache,"")!=0) strcatbuff(LINE,OPTIONcache);
  1692.   if(strcmp(OPTIONnorecatch,"")!=0) strcatbuff(LINE,OPTIONnorecatch);
  1693.   if(strcmp(OPTIONtestall,"")!=0) strcatbuff(LINE,OPTIONtestall);
  1694.   if(strcmp(OPTIONparseall,"")!=0) strcatbuff(LINE,OPTIONparseall);
  1695.   if(strcmp(OPTIONlink,"")!=0) strcatbuff(LINE,OPTIONlink);
  1696.   if(strcmp(OPTIONexternal,"")!=0) strcatbuff(LINE,OPTIONexternal);
  1697.   if(strcmp(OPTIONnopurge,"")!=0) strcatbuff(LINE,OPTIONnopurge);
  1698.   if(strcmp(OPTIONhidepwd,"")!=0) strcatbuff(LINE,OPTIONhidepwd);
  1699.   if(strcmp(OPTIONhidequery,"")!=0) strcatbuff(LINE,OPTIONhidequery);
  1700.   if(strcmp(OPTIONrobots,"")!=0) strcatbuff(LINE,OPTIONrobots);
  1701.   if(strcmp(OPTIONcookies,"")!=0) strcatbuff(LINE,OPTIONcookies);
  1702.   if(strcmp(OPTIONchecktype,"")!=0) strcatbuff(LINE,OPTIONchecktype);
  1703.   if(strcmp(OPTIONparsejava,"")!=0) strcatbuff(LINE,OPTIONparsejava);
  1704.   if(strcmp(OPTIONCache2,"")!=0) strcatbuff(LINE,OPTIONCache2);
  1705.   if(strcmp(OPTIONlogtype,"")!=0) strcatbuff(LINE,OPTIONlogtype);
  1706.   if (strlen(OPTIONhttp10)) strcatbuff(LINE,OPTIONhttp10);
  1707.   if (strlen(OPTIONtoler)) strcatbuff(LINE,OPTIONtoler);
  1708.   if (strlen(OPTIONupdhack)) strcatbuff(LINE,OPTIONupdhack);
  1709.   
  1710.   // si get, ne pas faire
  1711.   if (strcmp(choixdeb,"g")!=0) {
  1712.     if(build[0]=='-') {
  1713.       strcatbuff(LINE," ");
  1714.       strcatbuff(LINE,build);
  1715.       strcatbuff(LINE," -");
  1716.     } else if (strcmp(build,"")!=0) strcatbuff(LINE,build);
  1717.   }
  1718.   strcatbuff(LINE,OPTIONdos);
  1719.   strcatbuff(LINE,OPTIONindex);
  1720.   strcatbuff(LINE,OPTIONindex2);
  1721.   strcatbuff(LINE,OPTIONhtmlfirst);
  1722.   strcatbuff(LINE,filtre);
  1723.   strcatbuff(LINE,OPTIONmax);
  1724.   strcatbuff(LINE,OPTIONfrag);
  1725.   strcatbuff(LINE,OPTIONmaxfile);
  1726.   strcatbuff(LINE,OPTIONconn);
  1727.   strcatbuff(LINE,OPTIONtime);
  1728.   strcatbuff(LINE,OPTIONrate);
  1729.   strcatbuff(LINE,OPTIONretry);
  1730.   strcatbuff(LINE,OPTIONhostquit);
  1731.   strcatbuff(LINE,OPTIONka);
  1732.   strcatbuff(LINE,OPTIONlog);
  1733.   strcatbuff(LINE,OPTIONerrpage);
  1734.   //-->
  1735.   strcatbuff(LINE,OPTIONwaittime);
  1736.   strcatbuff(LINE,OPTIONmaxtime);
  1737.   strcatbuff(LINE,OPTIONmaxrate);
  1738.   strcatbuff(LINE,OPTIONmaxconn);
  1739.   strcatbuff(LINE,OPTIONmaxlinks);
  1740.   strcatbuff(LINE,OPTIONproxyftp);  
  1741.   strcatbuff(LINE,"#f");  // flush
  1742.   
  1743.   if (strcmp(OPTIONuser,"")!=0) {strcatbuff(LINE," ");strcatbuff(LINE,"-F");strcatbuff(LINE," ");strcatbuff(LINE,OPTIONuser);}
  1744.   if (strcmp(OPTIONfooter,"")!=0) {strcatbuff(LINE," ");strcatbuff(LINE,"-%F");strcatbuff(LINE," ");strcatbuff(LINE,OPTIONfooter);}
  1745.   
  1746.   if ((int)strlen(OPTIONproxy)>0) {
  1747.     strcatbuff(LINE," -P ");
  1748.     strcatbuff(LINE,OPTIONproxy);
  1749.     strcatbuff(LINE,":");
  1750.     strcatbuff(LINE,OPTIONport);
  1751.   }
  1752.   
  1753.   if (strnotempty(LANGUAGE_ISO)) {
  1754.     strcatbuff(LINE," -%l \"");
  1755.     strcatbuff(LINE,LANGUAGE_ISO);
  1756.     if (strcmp(LANGUAGE_ISO,"en")!=0)
  1757.       strcatbuff(LINE,", en");
  1758.     strcatbuff(LINE,", *\"");
  1759.   }
  1760.   
  1761.   // mode spider, mettre aprΦs options
  1762.   if (choixdeb[0]=='!') {
  1763.     strcatbuff(LINE," --testlinks");
  1764.   } else if (choixdeb[0]=='Y') {
  1765.     strcatbuff(LINE," --mirrorlinks");
  1766.   }
  1767.   
  1768.   // URLs!!
  1769.   strcatbuff(LINE," ");
  1770.   strcatbuff(LINE,OPTIONurl);
  1771.   
  1772.   // file list
  1773.   if ((int) strlen(OPTIONfilelist)>0) {
  1774.     strcatbuff(LINE," -%L \"");
  1775.     strcatbuff(LINE,OPTIONfilelist);
  1776.     strcatbuff(LINE,"\"");
  1777.   }
  1778.   
  1779.   // chemins
  1780.   if(strcmp(OPTIONpath,"")!=0) {
  1781.     strcatbuff(LINE," ");
  1782.     strcatbuff(LINE,"-O");
  1783.     strcatbuff(LINE," ");
  1784.     strcatbuff(LINE,OPTIONpath);
  1785.   }
  1786.   
  1787.   // buffer -> les + et -
  1788.   if(strcmp(buff_filtres,"")!=0) {
  1789.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1790.     strcatbuff(LINE," ");
  1791.     strcatbuff(LINE,buff_filtres );
  1792.   }
  1793.   
  1794.   // --assume
  1795.   if (strnotempty(buff_MIME)) {
  1796.     strcatbuff(LINE," ");
  1797.     strcatbuff(LINE,buff_MIME );
  1798.   }
  1799.   
  1800.   // ---
  1801.   
  1802.   //
  1803.   if (fp_debug) {
  1804.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1805.     fflush(fp_debug);
  1806.   }
  1807.   //
  1808.   // Θpurer cr,lf,tab - double espace -> espace
  1809.   {
  1810.     char *a;
  1811.     while(a=strchr(LINE,9)) *a=' ';
  1812.     while(a=strchr(LINE,10)) *a=' ';
  1813.     while(a=strchr(LINE,13)) *a=' ';
  1814.   }
  1815.   
  1816.   char LINE_back[65535];
  1817.   strcpybuff(LINE_back,LINE);
  1818.   
  1819.   // couper en morceaux
  1820.   {
  1821.     char* p=LINE;
  1822.     argv[0]="winhttrack";
  1823.     do {
  1824.       argv[argc++]=p;
  1825.       p=next_token(p,0);    // prochain token
  1826.       if (p) {
  1827.         *p=0;    // octet nul (tableau)
  1828.         p++;
  1829.       }            
  1830.     } while(p!=NULL);
  1831.   }
  1832.   
  1833.   //
  1834.   if (fp_debug) {
  1835.     fprintf(fp_debug,"Checking doit.log\r\n");
  1836.     fflush(fp_debug);
  1837.   }
  1838.   //
  1839.   // Ok, on lance!
  1840.   if(!termine) {
  1841.     int result=0;
  1842.     {
  1843.       char path_log[HTS_URLMAXSIZE*2];
  1844.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1845.       if (strlen(path_log)>0)
  1846.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1847.           strcatbuff(path_log,"/");
  1848.         
  1849.         // on efface le doit.log, pour annuler les parametres anciens et en redΘfinir de nouveaux
  1850.         // c'est ici une logique qui diffΦre de la version en ligne de commande
  1851.         //if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  1852.         if (fexist(fconcat(path_log,"hts-cache/new.ndx"))) {    // un cache est prΘsent
  1853.           if (fexist(fconcat(path_log,"hts-cache/doit.log")))
  1854.             remove(fconcat(path_log,"hts-cache/doit.log"));
  1855.           FILE* fp=fopen(fconcat(path_log,"hts-cache/doit.log"),"wb");
  1856.           if (fp) fclose(fp);
  1857.         }
  1858.         //}
  1859.     }
  1860.     
  1861.     
  1862.     // ---
  1863.     // LANCER LE MIROIR
  1864.     // ---
  1865.     //
  1866.     if (fp_debug) {
  1867.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1868.       fflush(fp_debug);
  1869.     }
  1870.     //
  1871. #if SHELL_MULTITHREAD
  1872.     Robot_params al;
  1873.     al.argc=argc;
  1874.     al.argv=argv;
  1875.     _beginthread( RunBackRobot     , 0, (void*) &al);
  1876.     //_beginthread( RefreshBackRobot , 0, NULL);
  1877.     
  1878.     //
  1879.     if (fp_debug) {
  1880.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  1881.       fflush(fp_debug);
  1882.     }
  1883.     //
  1884.     // domodal du refresh
  1885.     /* XXC A SUPPRIMER */
  1886.     while(!termine) {
  1887.       Sleep(100);
  1888.     }
  1889.     //inprogress->DoModal();
  1890.     WHTT_LOCK();
  1891.     shell_terminated=1;
  1892.     result=HTTRACK_result;
  1893.     termine=1;  
  1894.     WHTT_UNLOCK();
  1895.     //
  1896.     if (fp_debug) {
  1897.       fprintf(fp_debug,"Main dialog exited\r\n");
  1898.       fflush(fp_debug);
  1899.     }
  1900.     //
  1901.     
  1902.     // non multithread
  1903. #else
  1904. #error "Non supportΘ"
  1905. #endif
  1906.  
  1907.     /* Aborted mirror or finished? */
  1908.     {
  1909.       char path_log[HTS_URLMAXSIZE*2];
  1910.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1911.       if (strlen(path_log)>0)
  1912.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1913.           strcatbuff(path_log,"/");
  1914.         if (soft_term_requested || termine_requested) {
  1915.           FILE* fp=fopen(fconcat(path_log,"hts-cache/interrupted.lock"),"wb");
  1916.           if (fp)
  1917.             fclose(fp);
  1918.         } else
  1919.           remove(fconcat(path_log,"hts-cache/interrupted.lock"));
  1920.     }
  1921.     
  1922.     //SetForegroundWindow();   // yop en premier plan!
  1923.     //
  1924.     if (fp_debug) {
  1925.       fprintf(fp_debug,"Displaying end dialog\r\n");
  1926.       fflush(fp_debug);
  1927.     }
  1928.     //
  1929.     /* New pannel */
  1930.     if (result) {      // erreur?
  1931.       strcpybuff(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problΦme est survenu pendant le miroir\n  \""*/));
  1932.       strcatbuff(end_mirror_msg,"\"");
  1933.       strcatbuff(end_mirror_msg,hts_errmsg());
  1934.       strcatbuff(end_mirror_msg,"\"");
  1935.       strcatbuff(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  1936.       strcatbuff(end_mirror_msg,"\"");
  1937.       strcatbuff(end_mirror_msg,LINE_back);
  1938.       strcatbuff(end_mirror_msg,"\"");
  1939.       strcatbuff(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  1940.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  1941.     } else {
  1942.       strcpybuff(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminΘ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vΘrifier que tout s'est bien passΘ\n\nMerci d'utiliser WinHTTrack!"*/));
  1943.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  1944.       //        ShellExecute(0,"open",,"","",);
  1945.     }
  1946. #if USE_RAS
  1947.     // erreur ras
  1948.     if (connected == -1)
  1949.       if ((int) strlen(connected_err) > 0)
  1950.         strcpybuff(end_mirror_msg,connected_err);
  1951. #endif
  1952.       {
  1953.         char pathlog[HTS_URLMAXSIZE*2];
  1954.         strcpybuff(pathlog,dialog0->GetPath());
  1955.         Ciplog form;
  1956.         if (strlen(pathlog)>0)
  1957.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  1958.             strcatbuff(pathlog,"/");
  1959.           // fichier log existe ou on est tΘlΘcommandΘ par un !
  1960.           if ( (fsize(fconcat(pathlog,"hts-err.txt")))>0) {
  1961.             strcatbuff(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  1962.           }
  1963.       }
  1964.       //this_Cinfoend->m_infoend = msg;
  1965.       inprogress->SendMessage(WM_USER + 4);      // avertir
  1966.       if (fp_debug) {
  1967.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  1968.         fflush(fp_debug);
  1969.       }
  1970.       /*
  1971.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  1972.       // copie de onnewproject() de wid1::
  1973.       CWinApp* pApp = AfxGetApp();
  1974.       CString name = pApp->m_pszHelpFilePath;
  1975.       name=name.Left(name.GetLength()-4);
  1976.       name += ".EXE";
  1977.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  1978.       }
  1979.       */
  1980.       if (fp_debug) {
  1981.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  1982.         fflush(fp_debug);
  1983.       }
  1984.   }
  1985.   else {
  1986.   }
  1987.   
  1988. }
  1989.  
  1990. // int LANG_T(int);
  1991. // char* LANG(char* english,char* francais);
  1992.  
  1993.  
  1994. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  1995. void SetCombo(CWnd* _this,int id,char* lang_string) {
  1996.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  1997.   CString st=lang_string;
  1998.   st.TrimLeft(); st.TrimRight();
  1999.   if (combo) {
  2000.     st+="\n";         /* end */
  2001.     combo->ResetContent();
  2002.     while(st.GetLength()) {
  2003.       int pos=st.Find('\n');
  2004.       CString item=st.Left(pos);
  2005.       st=st.Mid(pos+1);
  2006.       item.TrimLeft(); item.TrimRight();
  2007.       if (item.GetLength())
  2008.         combo->AddString(item);
  2009.     }
  2010.   }
  2011. }
  2012.  
  2013.  
  2014. // Ecriture profiles
  2015. char* profile_code(char* from) {
  2016.   static char buff[65535];
  2017.   int i;
  2018.   int j;
  2019.   for(i=0,j=0;i<(int) strlen(from);i++) {
  2020.     switch(from[i]) {
  2021.     case '%': 
  2022.       buff[j++]='%';
  2023.       buff[j++]='%';
  2024.       break;
  2025.     case '=': 
  2026.       buff[j++]='%';
  2027.       buff[j++]='3';
  2028.       buff[j++]='d';
  2029.       break;
  2030.     case 13:
  2031.       buff[j++]='%';
  2032.       buff[j++]='0';
  2033.       buff[j++]='d';
  2034.       break;
  2035.     case 10:
  2036.       buff[j++]='%';
  2037.       buff[j++]='0';
  2038.       buff[j++]='a';
  2039.       break;
  2040.     case 9:
  2041.       buff[j++]='%';
  2042.       buff[j++]='0';
  2043.       buff[j++]='9';
  2044.       break;
  2045.     default:
  2046.       buff[j++]=from[i];
  2047.       break;
  2048.     }
  2049.   }
  2050.   buff[j++]='\0';
  2051.   return buff;
  2052. }
  2053. char* profile_decode(char* from) {
  2054.   static char buff[2048];
  2055.   int i;
  2056.   int j;
  2057.   for(i=0,j=0;j<(int) strlen(from);i++) {  // oui oui
  2058.     if (from[j]=='%') {
  2059.       if (from[j+1]=='%') {
  2060.         buff[i]='%';
  2061.         j+=2;
  2062.       } else {
  2063.         if (strncmp(from+j+1,"0d",2)==0)
  2064.           buff[i]=13;
  2065.         else if (strncmp(from+j+1,"0a",2)==0)
  2066.           buff[i]=10;
  2067.         else if (strncmp(from+j+1,"09",2)==0)
  2068.           buff[i]=9;
  2069.         else if (strncmp(from+j+1,"3d",2)==0)
  2070.           buff[i]='=';
  2071.         else
  2072.           buff[i]=' ';
  2073.         j+=3;
  2074.       }
  2075.     } else
  2076.       buff[i]=from[j++];
  2077.   }
  2078.   buff[i++]='\0';
  2079.   return buff;
  2080. }
  2081. //
  2082. // Ecriture/Lecture profiles
  2083. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  2084.   if (path.IsEmpty()) {
  2085.     CWinApp* pApp = AfxGetApp();
  2086.     pApp->WriteProfileInt(dummy,name,value);
  2087.   } else if (path=="<mem>") {       // buffer
  2088.     tmpm.setInt(name,value);
  2089.     return 0;
  2090.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2091.     if (tmpf) {
  2092.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2093.     }
  2094.   } else {
  2095.     FILE* fp = fopen(path,"ab");
  2096.     if (fp) {
  2097.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2098.       /*
  2099.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2100.       */
  2101.       fclose(fp);
  2102.       return r;
  2103.     }
  2104.   }
  2105.   return 0;
  2106. }
  2107. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2108.   if (fp) {
  2109.     fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2110.   }
  2111.   return 0;
  2112. }
  2113. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2114.   if (path.IsEmpty()) {
  2115.     CWinApp* pApp = AfxGetApp();
  2116.     char *tempo;
  2117.     tempo=(char*) malloc(strlen(value)+1);
  2118.     if (tempo) {
  2119.       strcpybuff(tempo,value);
  2120.       pApp->WriteProfileString(dummy,name,profile_code(tempo));
  2121.     } else
  2122.       return -1;      // error
  2123.   } else if (path=="<mem>") {       // buffer
  2124.     tmpm.setString(name,value);
  2125.     return 0;
  2126.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2127.     if (tmpf) {
  2128.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2129.     }
  2130.   } else {
  2131.     FILE* fp = fopen(path,"ab");
  2132.     if (fp) {
  2133.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2134.       /*
  2135.       char *tempo;
  2136.       tempo=(char*) malloc(strlen(value)+1);
  2137.       if (tempo) {
  2138.       strcpybuff(tempo,value);
  2139.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2140.       fclose(fp);
  2141.       free(tempo);
  2142.       } else
  2143.       return -1;      // error
  2144.       */
  2145.       fclose(fp);
  2146.       return r;
  2147.     }
  2148.   }
  2149.   return 0;
  2150. }
  2151. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2152.   if (fp) {
  2153.     char *tempo;
  2154.     tempo=(char*) malloc(strlen(value)+1);
  2155.     if (tempo) {
  2156.       strcpybuff(tempo,value);
  2157.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2158.       free(tempo);
  2159.     } else
  2160.       return -1;      // error
  2161.   }
  2162.   return 0;
  2163. }
  2164. //
  2165. // lecture
  2166. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2167.   if (path.IsEmpty()) {
  2168.     CWinApp* pApp = AfxGetApp();
  2169.     return pApp->GetProfileInt(dummy,name,value);
  2170.   } else if (path=="<mem>") {       // buffer
  2171.     return tmpm.getInt(name,value);
  2172.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2173.     if (tmpf) {
  2174.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2175.     } else return value;
  2176.   } else {
  2177.     FILE* fp = fopen(path,"rb");
  2178.     if (fp) {
  2179.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2180.       /*
  2181.       char srch[256];
  2182.       sprintf(srch,"%s=",name);
  2183.       while(!feof(fp)) {
  2184.       char s[HTS_URLMAXSIZE*2];
  2185.       linput(fp,s,1020);
  2186.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2187.       int val;
  2188.       if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2189.       return val;
  2190.       else
  2191.       return value;
  2192.       }
  2193.       }
  2194.       fclose(fp);
  2195.       return value;
  2196.       */
  2197.       fclose(fp);
  2198.       return r;
  2199.     } else return value;
  2200.   }
  2201. }
  2202. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2203.   if (fp) {
  2204.     char srch[256];
  2205.     fseek(fp,0,SEEK_SET);
  2206.     sprintf(srch,"%s=",name);
  2207.     while(!feof(fp)) {
  2208.       char s[2048]; s[0]='\0';
  2209.       linput(fp,s,2000);
  2210.       if (strlen(s)==0)     // EOF
  2211.         return value;
  2212.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2213.         int val;
  2214.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2215.           return val;
  2216.         else
  2217.           return value;
  2218.       }
  2219.     }
  2220.     return value;
  2221.   } else return value;
  2222. }
  2223. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2224.   if (path.IsEmpty()) {
  2225.     CWinApp* pApp = AfxGetApp();
  2226.     char tempo[32768];
  2227.     char value_default[32768];
  2228.     strcpybuff(value_default,value);
  2229.     strcpybuff(tempo,pApp->GetProfileString(dummy,name,profile_code(value_default)));
  2230.     return profile_decode(tempo);
  2231.   } else if (path=="<mem>") {       // buffer
  2232.     return tmpm.getString(name,value);
  2233.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2234.     if (tmpf) {
  2235.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2236.     } else return value;
  2237.   } else {
  2238.     FILE* fp = fopen(path,"rb");
  2239.     if (fp) {
  2240.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2241.       /*
  2242.       char srch[256];
  2243.       sprintf(srch,"%s",name);
  2244.       strcatbuff(srch,"=");
  2245.       while(!feof(fp)) {
  2246.       char s[32768];
  2247.       linput(fp,s,32000);
  2248.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2249.       return profile_decode(s+strlen(srch));
  2250.       }
  2251.       }
  2252.       fclose(fp);
  2253.       return value;
  2254.       */
  2255.       fclose(fp);
  2256.       return st;
  2257.     } else return value;
  2258.   }
  2259. }
  2260. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2261.   if (fp) {
  2262.     char srch[256];
  2263.     fseek(fp,0,SEEK_SET);
  2264.     sprintf(srch,"%s",name);
  2265.     strcatbuff(srch,"=");
  2266.     while(!feof(fp)) {
  2267.       char s[32768]; s[0]='\0';
  2268.       linput(fp,s,32000);
  2269.       if (strlen(s)==0)     // EOF
  2270.         return value;
  2271.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2272.         return profile_decode(s+strlen(srch));
  2273.       }
  2274.     }
  2275.     return value;
  2276.   } else return value;
  2277. }
  2278.  
  2279. //
  2280. // Get_profile et Write_profile eux mΩmes
  2281. //
  2282. // path="" -> Θcrire dans la base (default)
  2283. // path="<tmp>" -> Θcrire dans le fichier tempo commun
  2284. // path="<mem>" -> Θcrire dans le buffer tempo commun
  2285. // path="<null>" -> lire default (illΘgal en Θcriture)
  2286. void Write_profile(CString path,int load_path) {
  2287.   CWaitCursor wait;
  2288.   CString strSection       = "OptionsValues";
  2289.   CString st;
  2290.   int n;
  2291.   
  2292.   // Fichier tempo ou fichier?
  2293.   if (path=="<tmp>") {     // fichier temporaire
  2294.     if (tmpf)
  2295.       fclose(tmpf);
  2296.     tmpf=tmpfile();
  2297.     if (!tmpf)
  2298.       return;
  2299.   } else if (path=="<mem>") {     // buffer temporaire
  2300.     tmpm.deleteAll();
  2301.   } else if (!(path.IsEmpty())) {
  2302.     FILE *fp=fopen(path,"wb");
  2303.     if (fp) 
  2304.       fclose(fp);
  2305.   }
  2306.   
  2307.   //if (dialog3.m_hWnd == NULL) {    // pas initialisΘ
  2308.   if (maintab->m_hWnd == NULL) {    // pas initialisΘ
  2309.     // checkboxes
  2310.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2311.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2312.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2313.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2314.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2315.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2316.     MyWriteProfileInt(path,strSection, "Dos",
  2317.       ((maintab->m_option2.m_dos)?1:0)
  2318.       +
  2319.       (((maintab->m_option2.m_iso9660)?1:0)<<1)
  2320.       );
  2321.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2322.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2323.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2324.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2325.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2326.     MyWriteProfileInt(path,strSection, "KeepAlive",maintab->m_option4.m_ka);
  2327.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2328.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2329.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2330.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2331.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2332.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2333.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2334.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2335.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2336.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2337.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2338.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2339.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2340.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2341.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2342.     
  2343.     // menus
  2344.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2345.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2346.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2347.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2348.     MyWriteProfileInt(path,strSection, "RewriteLinks",maintab->m_option3.m_travel3);
  2349.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2350.     
  2351.     // champs
  2352.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2353.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2354.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2355.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2356.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2357.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2358.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2359.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2360.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2361.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2362.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2363.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2364.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2365.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2366.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2367.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2368.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2369.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2370.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2371.     
  2372.     // 11
  2373.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2374.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2375.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2376.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2377.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2378.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2379.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2380.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2381.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2382.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2383.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2384.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2385.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2386.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2387.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2388.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);    
  2389.   } else {
  2390.     // checkboxes
  2391.     // 1
  2392.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2393.     MyWriteProfileInt(path,strSection,"Near", n);
  2394.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2395.     MyWriteProfileInt(path,strSection,"Test", n);
  2396.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2397.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2398.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2399.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2400.     // 2
  2401.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2402.     MyWriteProfileInt(path,strSection,"Cache", n);
  2403.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2404.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2405.     n = ((maintab->m_option2.IsDlgButtonChecked(IDC_dos))?1:0)
  2406.       + ((maintab->m_option2.IsDlgButtonChecked(IDC_iso9660)?1:0)<<1);
  2407.     MyWriteProfileInt(path,strSection,"Dos", n);
  2408.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2409.     MyWriteProfileInt(path,strSection,"Index", n);
  2410.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2411.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2412.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2413.     MyWriteProfileInt(path,strSection,"Log", n);
  2414.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2415.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2416.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2417.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2418.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2419.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2420.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2421.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2422.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2423.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2424.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2425.       MyWriteProfileInt(path,strSection, "Build", n);
  2426.     st = maintab->m_option2.Bopt.m_BuildString;
  2427.     if (st.GetLength()>0)
  2428.       MyWriteProfileString(path,strSection, "BuildString",st);
  2429.     // 3
  2430.     // menus
  2431.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2432.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2433.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2434.       MyWriteProfileInt(path,strSection, "Travel", n);
  2435.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2436.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2437.     if ((n=maintab->m_option3.m_ctl_travel3.GetCurSel()) != CB_ERR)
  2438.       MyWriteProfileInt(path,strSection, "RewriteLinks", n);
  2439.     //
  2440.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2441.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2442.     // 4
  2443.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2444.     MyWriteProfileString(path,strSection, "Sockets", st);
  2445.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2446.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2447.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2448.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2449.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2450.     MyWriteProfileString(path,strSection, "Retry", st);
  2451.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2452.     MyWriteProfileString(path,strSection, "RateOut", st);
  2453.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2454.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2455.     n=maintab->m_option4.IsDlgButtonChecked(IDC_ka);
  2456.     MyWriteProfileInt(path,strSection,"KeepAlive", n);
  2457.     // 5
  2458.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2459.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2460.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2461.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2462.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2463.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2464.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2465.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2466.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2467.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2468.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2469.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2470.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2471.     MyWriteProfileString(path,strSection,"Depth",st);
  2472.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2473.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2474.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2475.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2476.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2477.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2478.     // 6
  2479.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2480.     MyWriteProfileString(path,strSection, "UserID", st);
  2481.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2482.     MyWriteProfileString(path,strSection, "Footer", st);
  2483.     // 7
  2484.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2485.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2486.     // 8
  2487.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2488.     MyWriteProfileString(path,strSection, "Cookies", st);
  2489.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2490.     MyWriteProfileString(path,strSection, "CheckType", st);
  2491.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2492.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2493.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2494.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2495.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2496.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2497.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2498.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2499.     // 9
  2500.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2501.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2502.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2503.     MyWriteProfileString(path,strSection, "LogType", st);
  2504.     // 10
  2505.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2506.     MyWriteProfileString(path,strSection,"Proxy",st);
  2507.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2508.     MyWriteProfileString(path,strSection,"Port",st);
  2509.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2510.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2511.     
  2512.     // 11
  2513.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2514.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2515.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2516.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2517.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2518.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2519.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2520.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2521.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2522.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2523.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2524.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2525.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2526.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2527.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2528.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2529.   }
  2530.   // liens, jokers etc. si mirror merge
  2531.   if (!(path.IsEmpty())) {
  2532.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2533.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2534.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2535.       if (dialog1->m_todo >= 0)
  2536.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2537.       //
  2538.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2539.       
  2540.       //if (load_path) {
  2541.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2542.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2543.       //}
  2544.     } else {
  2545.       //dialog1->GetDlgItemText(IDC_depth,st);
  2546.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2547.       dialog1->GetDlgItemText(IDC_URL,st);
  2548.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2549.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2550.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2551.       //
  2552.       dialog1->GetDlgItemText(IDC_filelist,st);
  2553.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2554.       //
  2555.       //if (load_path) {
  2556.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2557.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2558.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2559.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2560.       //}
  2561.     }
  2562.   }
  2563. }
  2564. // path="" -> lire dans la base (default)
  2565. //if not exist: do not load anything but patches projname&co
  2566. void Read_profile(CString path,int load_path) {
  2567.   CWaitCursor wait;
  2568.   CString strSection       = "OptionsValues";
  2569.   CString st;
  2570.   
  2571.   // VΘrification <tmp>
  2572.   if (path=="<tmp>") {     // fichier temporaire
  2573.     if (!tmpf)
  2574.       return;
  2575.     else
  2576.       fflush(tmpf);
  2577.   } else if (path=="<null>") {     // options par dΘfaut
  2578.     path="<mem>";
  2579.     tmpm.deleteAll();              // effacer
  2580.   } else {
  2581.     int pos=path.ReverseFind('\\');
  2582.     if (pos>=0) {
  2583.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2584.       pos=dir.ReverseFind('\\');
  2585.       if (pos>=0) {
  2586.         dir=dir.Left(pos);                  // enlever hts-cache
  2587.         pos=dir.ReverseFind('\\');
  2588.         if (pos>=0) {
  2589.           dialog0->m_projname=dir.Mid(pos+1);
  2590.           dialog0->m_projpath=dir.Left(pos);
  2591.           /*
  2592.           if (this_CWizTab)
  2593.           this_CWizTab->SetActivePage(2);     // page 3
  2594.           */
  2595.         }
  2596.       }
  2597.     }
  2598.   }
  2599.   
  2600.   // checkboxes
  2601.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2602.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2603.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2604.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2605.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2606.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2607.   maintab->m_option2.m_dos       = (MyGetProfileInt(path,strSection, "Dos",0) & 1);
  2608.   maintab->m_option2.m_iso9660   = ((MyGetProfileInt(path,strSection, "Dos",0) & 2)>>1);
  2609.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2610.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2611.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2612.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2613.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2614.   maintab->m_option4.m_ka        = MyGetProfileInt(path,strSection, "KeepAlive",1);
  2615.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2616.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2617.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2618.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2619.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2620.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2621.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2622.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2623.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2624.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2625.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2626.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2627.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2628.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2629.   
  2630.   // menus
  2631.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2632.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2633.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2634.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2635.   maintab->m_option3.m_travel3 = MyGetProfileInt(path,strSection, "RewriteLinks",0);
  2636.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2637.   
  2638.   // champs
  2639.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2640.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2641.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2642.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2643.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2644.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2645.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2646.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2647.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2648.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2649.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2650.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate", "25000");
  2651.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2652.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2653.   
  2654.   // 7
  2655.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*");
  2656.   
  2657.   // 10
  2658.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2659.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2660.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2661.   //
  2662.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2663.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2664.   
  2665.   // 11
  2666.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1", "php3,php,php2,asp,jsp,pl,cfm");
  2667.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2668.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2669.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2670.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2671.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2672.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2673.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2674.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1", "text/html");
  2675.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2676.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2677.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2678.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2679.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2680.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2681.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2682.   
  2683.   
  2684.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2685.   //strcpybuff(buff_filtres,st);
  2686.   
  2687.   // liens, jokers etc. si mirror merge
  2688.   if (!(path.IsEmpty())) {
  2689.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2690.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2691.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2692.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2693.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2694.       /*
  2695.       if (load_path) {
  2696.       CString st;
  2697.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2698.       if (st != "")
  2699.       dialog1->m_pathlog = st;
  2700.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2701.       if (st != "")
  2702.       dialog1->m_pathmir = st;
  2703.       }
  2704.       */
  2705.     } else {
  2706.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2707.       //dialog1->SetDlgItemText(IDC_depth,st);
  2708.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2709.       dialog1->SetDlgItemText(IDC_URL,st);
  2710.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2711.       dialog1->m_ctl_todo.SetCurSel(n);
  2712.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2713.       dialog1->SetDlgItemText(IDC_filelist,st);
  2714.       /*
  2715.       if (load_path) {
  2716.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2717.       if (st != "")
  2718.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2719.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2720.       if (st != "")
  2721.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2722.       }
  2723.       */
  2724.       dialog1->Refresh();
  2725.     }
  2726.   }
  2727.   
  2728. }
  2729.  
  2730. // Initialisation du RAS
  2731. void InitRAS() {
  2732. #if USE_RAS
  2733.   if (!LibRas) {
  2734.     LibRas=new CDynamicRAS();
  2735.     if (LibRas->IsRASLoaded()) 
  2736.       LibRasUse=1;
  2737.     else
  2738.       LibRasUse=0;
  2739.   }
  2740. #endif
  2741. }
  2742.  
  2743. // Reconstruire index gΘnΘral!
  2744. void Build_TopIndex(BOOL check_empty) {
  2745.   CWaitCursor wait;
  2746.  
  2747.   //if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2748.   {
  2749.     char path[HTS_URLMAXSIZE*2];
  2750.     strcpybuff(path,CShellApp_app->end_path);
  2751.  
  2752.     /* Build top index */
  2753.     hts_buildtopindex(path, "");
  2754.  
  2755.     /* Check empty dirs and build .whtt */
  2756.     // FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2757.     //if (fpo) {
  2758.     {
  2759.       // verif_backblue(path);    // gΘnΘrer gif
  2760.       //
  2761.       // Header
  2762.       //fprintf(fpo,toptemplate_header,
  2763.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2764.       //  );
  2765.       // chargement de la liste
  2766.       WIN32_FIND_DATA find;
  2767.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2768.       if (h != INVALID_HANDLE_VALUE) {
  2769.         CString to_delete="";
  2770.         do {
  2771.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2772.             if (strcmp(find.cFileName,".."))
  2773.               if (strcmp(find.cFileName,"."))
  2774.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2775.                   int r;
  2776.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2777.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2778.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2779.                   } else {      /* non vide */
  2780.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2781.                     strcpybuff(iname,CShellApp_app->end_path);
  2782.                     strcatbuff(iname,find.cFileName);
  2783.                     strcatbuff(iname,"\\");
  2784.                     strcpybuff(iname2,iname);
  2785.                     strcatbuff(iname,"index.html");
  2786.                     strcatbuff(iname2,"\\hts-cache\\winprofile.ini");
  2787.                     if (fexist(iname)) {
  2788.                       char hname[HTS_URLMAXSIZE*2];
  2789.                       strcpybuff(hname,find.cFileName);
  2790.                       escape_check_url(hname);
  2791.                       // Body
  2792.                       //fprintf(fpo,toptemplate_body,
  2793.                       //  hname,
  2794.                       //  find.cFileName
  2795.                       //  );
  2796.                     }
  2797.                     
  2798.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2799.                       // vΘrifier existence de .whtt
  2800.                       strcpybuff(iname,CShellApp_app->end_path);
  2801.                       strcatbuff(iname,find.cFileName);
  2802.                       strcatbuff(iname,".whtt");
  2803.                       if (!fexist(iname)) {
  2804.                         FILE* fp=fopen(iname,"wb");
  2805.                         if (fp) fclose(fp);
  2806.                       }
  2807.                       
  2808.                     }
  2809.                   }
  2810.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2811.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2812.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2813.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2814.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2815.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2816.                       remove(iname);
  2817.                     }
  2818.                   }
  2819.                 }
  2820.         } while(FindNextFile(h,&find));
  2821.         FindClose(h);
  2822.         if (check_empty) {
  2823.           while(to_delete.GetLength()>0) {
  2824.             int pos=to_delete.Find('\n');
  2825.             if (pos) {
  2826.               CString path=to_delete.Left(pos);
  2827.               to_delete=to_delete.Mid(pos+1);
  2828.               CString str;
  2829.               str.Format(LANG_DELETEEMPTYCONF,path);
  2830.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2831.                 /* Θliminer au besoin le .whtt */
  2832.                 DeleteFile(path+".whtt");
  2833.                 if (!RemoveEmptyDir(path))
  2834.                   AfxMessageBox(LANG_ERRORDEL);
  2835.               }
  2836.             } else
  2837.               to_delete="";
  2838.           }
  2839.         }
  2840.       }
  2841.       // Footer
  2842.       //fprintf(fpo,toptemplate_footer,
  2843.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2844.       //  );
  2845.       //fclose(fpo);
  2846.     }
  2847.     
  2848.   }
  2849.  
  2850.   /*
  2851.   if (toptemplate_header)
  2852.     freet(toptemplate_header);
  2853.   if (toptemplate_body)
  2854.     freet(toptemplate_body);
  2855.   if (toptemplate_footer)
  2856.     freet(toptemplate_footer);
  2857.   */
  2858. }
  2859.  
  2860. /*
  2861. -1 : error
  2862. 0 : directory is empty
  2863. 1 : empty directories inside
  2864. 2 : empty files inside
  2865. 3 : 1 + 2
  2866. 4 : not empty
  2867. */
  2868. int CheckDirInfo(CString path) {
  2869.   CWaitCursor wait;
  2870.   
  2871.   if (path.Right(1)!="\\")
  2872.     path+="\\";
  2873.   
  2874.   // Pour FindFirstFile/FindNextFile
  2875.   WIN32_FIND_DATA find;
  2876.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2877.   
  2878.   // accessible
  2879.   if (h!=INVALID_HANDLE_VALUE) {
  2880.     int return_code=0;
  2881.     do {
  2882.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2883.         if (strcmp(find.cFileName,"..")) {
  2884.           if (strcmp(find.cFileName,".")) {
  2885.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2886.               return_code|=1;
  2887.               int r=CheckDirInfo(path+find.cFileName);
  2888.               if (r==4)
  2889.                 return_code=4;
  2890.               else
  2891.                 return_code|=r;
  2892.             } else {
  2893.               return_code|=2;
  2894.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2895.                 return_code=4;
  2896.             }
  2897.           }
  2898.         }
  2899.       }
  2900.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2901.     FindClose(h);
  2902.     return return_code;
  2903.   } else
  2904.     return -1;
  2905. }
  2906.  
  2907. /*
  2908. Remove Empty Dir
  2909. */
  2910. BOOL RemoveEmptyDir(CString path) {
  2911.   CWaitCursor wait;
  2912.   
  2913.   SetCurrentDirectory("C:\\");
  2914.   
  2915.   if (path.Right(1)!="\\")
  2916.     path+="\\";
  2917.   
  2918.   // Pour FindFirstFile/FindNextFile
  2919.   WIN32_FIND_DATA find;
  2920.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2921.   
  2922.   // accessible
  2923.   if (h!=INVALID_HANDLE_VALUE) {
  2924.     do {
  2925.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2926.         if (strcmp(find.cFileName,"..")) {
  2927.           if (strcmp(find.cFileName,".")) {
  2928.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2929.               if (!RemoveEmptyDir(path+find.cFileName)) {
  2930.                 FindClose(h);
  2931.                 return 0;
  2932.               }
  2933.             } else {
  2934.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  2935.                 if (!DeleteFile(path+find.cFileName)) {
  2936.                   FindClose(h);
  2937.                   return 0;
  2938.                 }
  2939.             }
  2940.           }
  2941.         }
  2942.       }
  2943.     } while(FindNextFile(h,&find));
  2944.     FindClose(h);
  2945.     
  2946.     SetCurrentDirectory("C:\\");
  2947.     return RemoveDirectory(path.Left(path.GetLength()-1));
  2948.   } else
  2949.     return 0;
  2950.   return TRUE;
  2951. }
  2952.